Merge pull request #311 from murgatroid99/node_fix_not_found_handler

Added handling for unimplemeneted methods on the server
This commit is contained in:
Tim Emiola 2015-01-30 19:16:36 -08:00
commit 7ba9ae86d2
2 changed files with 21 additions and 4 deletions

View File

@ -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));
}

View File

@ -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 */