Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/grpc: return original error message #1433

Merged
merged 1 commit into from
Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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