From 0af89aa5586817a19297aa18a63c61ba881bc88b Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 30 Jan 2015 14:13:11 -0800 Subject: [PATCH] Added handling for unimplemeneted methods on the server --- src/node/src/server.js | 17 +++++++++++++---- src/node/test/client_server_test.js | 8 ++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/node/src/server.js b/src/node/src/server.js index a5d737c68d3..e4f71ff05f7 100644 --- a/src/node/src/server.js +++ b/src/node/src/server.js @@ -243,15 +243,24 @@ function Server(getMetadata, options) { var handler = undefined; var deadline = data.absolute_deadline; var cancelled = false; - if (handlers.hasOwnProperty(data.method)) { - handler = handlers[data.method]; - } call.serverAccept(function(event) { if (event.data.code === grpc.status.CANCELLED) { cancelled = true; - stream.emit('cancelled'); + if (stream) { + stream.emit('cancelled'); + } } }, 0); + if (handlers.hasOwnProperty(data.method)) { + handler = handlers[data.method]; + } else { + call.serverEndInitialMetadata(0); + call.startWriteStatus( + grpc.status.UNIMPLEMENTED, + "This method is not available on this server.", + function() {}); + return; + } if (getMetadata) { call.addMetadata(getMetadata(data.method, data.metadata)); } diff --git a/src/node/test/client_server_test.js b/src/node/test/client_server_test.js index 059dd1323af..1db9f694678 100644 --- a/src/node/test/client_server_test.js +++ b/src/node/test/client_server_test.js @@ -185,6 +185,14 @@ describe('echo client', function() { done(); }); }); + it('should get correct status for unimplemented method', function(done) { + var stream = client.makeRequest(channel, 'unimplemented_method'); + stream.end(); + stream.on('status', function(status) { + assert.equal(status.code, grpc.status.UNIMPLEMENTED); + done(); + }); + }); }); /* TODO(mlumish): explore options for reducing duplication between this test * and the insecure echo client test */