From 9845887968de6aff27337fe31336dae031981089 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 8 Jul 2015 09:17:39 -0700 Subject: [PATCH 1/3] Made Node server respond with UNKNOWN for unspecified application errors --- src/server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server.js b/src/server.js index c6cf9e7e..62a107c8 100644 --- a/src/server.js +++ b/src/server.js @@ -55,7 +55,7 @@ var EventEmitter = require('events').EventEmitter; */ function handleError(call, error) { var status = { - code: grpc.status.INTERNAL, + code: grpc.status.UNKNOWN, details: 'Unknown Error', metadata: {} }; @@ -142,12 +142,12 @@ function setUpWritable(stream, serialize) { stream.on('finish', sendStatus); /** * Set the pending status to a given error status. If the error does not have - * code or details properties, the code will be set to grpc.status.INTERNAL + * code or details properties, the code will be set to grpc.status.UNKNOWN * and the details will be set to 'Unknown Error'. * @param {Error} err The error object */ function setStatus(err) { - var code = grpc.status.INTERNAL; + var code = grpc.status.UNKNOWN; var details = 'Unknown Error'; var metadata = {}; if (err.hasOwnProperty('message')) { From f4c2b5a0ace6322ab355c189c0e438581a9ccb2d Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 17 Jul 2015 11:26:54 -0700 Subject: [PATCH 2/3] Add tests for translating server handler errors to status objects --- test/surface_test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/surface_test.js b/test/surface_test.js index 8d1f99aa..ce388ab3 100644 --- a/test/surface_test.js +++ b/test/surface_test.js @@ -418,6 +418,44 @@ describe('Other conditions', function() { }); }); }); + describe('Error object should contain the status', function() { + it('for a unary call', function(done) { + client.unary({error: true}, function(err, data) { + assert(err); + assert.strictEqual(err.message, 'Requested error'); + done(); + }); + }); + it('for a client stream call', function(done) { + var call = client.clientStream(function(err, data) { + assert(err); + assert.strictEqual(err.message, 'Requested error'); + done(); + }); + call.write({error: false}); + call.write({error: true}); + call.end(); + }); + it('for a server stream call', function(done) { + var call = client.serverStream({error: true}); + call.on('data', function(){}); + call.on('error', function(error) { + assert.strictEqual(error.message, 'Requested error'); + done(); + }); + }); + it('for a bidi stream call', function(done) { + var call = client.bidiStream(); + call.write({error: false}); + call.write({error: true}); + call.end(); + call.on('data', function(){}); + call.on('error', function(error) { + assert.strictEqual(error.message, 'Requested error'); + done(); + }); + }); + }); }); describe('Cancelling surface client', function() { var client; From 196f96c61eeb6d98d77cfd6b17ab3137f4a35218 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 17 Jul 2015 13:06:15 -0700 Subject: [PATCH 3/3] Added tests for UNKNOWN status when the handler does not specify --- test/surface_test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/surface_test.js b/test/surface_test.js index ce388ab3..12595727 100644 --- a/test/surface_test.js +++ b/test/surface_test.js @@ -422,6 +422,7 @@ describe('Other conditions', function() { it('for a unary call', function(done) { client.unary({error: true}, function(err, data) { assert(err); + assert.strictEqual(err.code, grpc.status.UNKNOWN); assert.strictEqual(err.message, 'Requested error'); done(); }); @@ -429,6 +430,7 @@ describe('Other conditions', function() { it('for a client stream call', function(done) { var call = client.clientStream(function(err, data) { assert(err); + assert.strictEqual(err.code, grpc.status.UNKNOWN); assert.strictEqual(err.message, 'Requested error'); done(); }); @@ -440,6 +442,7 @@ describe('Other conditions', function() { var call = client.serverStream({error: true}); call.on('data', function(){}); call.on('error', function(error) { + assert.strictEqual(error.code, grpc.status.UNKNOWN); assert.strictEqual(error.message, 'Requested error'); done(); }); @@ -451,6 +454,7 @@ describe('Other conditions', function() { call.end(); call.on('data', function(){}); call.on('error', function(error) { + assert.strictEqual(error.code, grpc.status.UNKNOWN); assert.strictEqual(error.message, 'Requested error'); done(); });