Skip to content

Commit

Permalink
core/grpc: return original error message (googleapis#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and callmehiphop committed Jul 15, 2016
1 parent b585b3a commit d995fb6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/common/grpc-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

'use strict';

var extend = require('extend');
var googleProtoFiles = require('google-proto-files');
var grpc = require('grpc');
var is = require('is');
Expand Down Expand Up @@ -456,9 +455,13 @@ GrpcService.createDeadline_ = function(timeout) {
* @return {error|null}
*/
GrpcService.getError_ = function(err) {
if (GRPC_ERROR_CODE_TO_HTTP[err.code]) {
return extend(true, {}, err, GRPC_ERROR_CODE_TO_HTTP[err.code]);
if (err && GRPC_ERROR_CODE_TO_HTTP[err.code]) {
var defaultErrorDetails = GRPC_ERROR_CODE_TO_HTTP[err.code];
err.code = defaultErrorDetails.code;
err.message = err.message || defaultErrorDetails.message;
return err;
}

return null;
};

Expand Down
14 changes: 13 additions & 1 deletion test/common/grpc-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,19 @@ describe('GrpcService', function() {
});
});

it('should return null for unknown errors', function() {
it('should use the message from the error', function() {
var errorMessage = 'This is an error message.';

var err = {
code: 1,
message: errorMessage
};

var error = GrpcService.getError_(err);
assert.strictEqual(error.message, errorMessage);
});

it('should return the original object for unknown errors', function() {
var error = GrpcService.getError_({ code: 9999 });

assert.strictEqual(error, null);
Expand Down

0 comments on commit d995fb6

Please sign in to comment.