Skip to content
Snippets Groups Projects
Commit fd98ac80 authored by Tim Emiola's avatar Tim Emiola
Browse files

Merge pull request #311 from murgatroid99/node_fix_not_found_handler

Added handling for unimplemeneted methods on the server
parents be915471 0af89aa5
No related branches found
No related tags found
No related merge requests found
...@@ -243,15 +243,24 @@ function Server(getMetadata, options) { ...@@ -243,15 +243,24 @@ function Server(getMetadata, options) {
var handler = undefined; var handler = undefined;
var deadline = data.absolute_deadline; var deadline = data.absolute_deadline;
var cancelled = false; var cancelled = false;
if (handlers.hasOwnProperty(data.method)) {
handler = handlers[data.method];
}
call.serverAccept(function(event) { call.serverAccept(function(event) {
if (event.data.code === grpc.status.CANCELLED) { if (event.data.code === grpc.status.CANCELLED) {
cancelled = true; cancelled = true;
stream.emit('cancelled'); if (stream) {
stream.emit('cancelled');
}
} }
}, 0); }, 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) { if (getMetadata) {
call.addMetadata(getMetadata(data.method, data.metadata)); call.addMetadata(getMetadata(data.method, data.metadata));
} }
......
...@@ -185,6 +185,14 @@ describe('echo client', function() { ...@@ -185,6 +185,14 @@ describe('echo client', function() {
done(); 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 /* TODO(mlumish): explore options for reducing duplication between this test
* and the insecure echo client test */ * and the insecure echo client test */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment