Skip to content

Commit d995fb6

Browse files
stephenpluspluscallmehiphop
authored andcommitted
core/grpc: return original error message (#1433)
1 parent b585b3a commit d995fb6

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/common/grpc-service.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
'use strict';
2222

23-
var extend = require('extend');
2423
var googleProtoFiles = require('google-proto-files');
2524
var grpc = require('grpc');
2625
var is = require('is');
@@ -456,9 +455,13 @@ GrpcService.createDeadline_ = function(timeout) {
456455
* @return {error|null}
457456
*/
458457
GrpcService.getError_ = function(err) {
459-
if (GRPC_ERROR_CODE_TO_HTTP[err.code]) {
460-
return extend(true, {}, err, GRPC_ERROR_CODE_TO_HTTP[err.code]);
458+
if (err && GRPC_ERROR_CODE_TO_HTTP[err.code]) {
459+
var defaultErrorDetails = GRPC_ERROR_CODE_TO_HTTP[err.code];
460+
err.code = defaultErrorDetails.code;
461+
err.message = err.message || defaultErrorDetails.message;
462+
return err;
461463
}
464+
462465
return null;
463466
};
464467

test/common/grpc-service.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,19 @@ describe('GrpcService', function() {
11331133
});
11341134
});
11351135

1136-
it('should return null for unknown errors', function() {
1136+
it('should use the message from the error', function() {
1137+
var errorMessage = 'This is an error message.';
1138+
1139+
var err = {
1140+
code: 1,
1141+
message: errorMessage
1142+
};
1143+
1144+
var error = GrpcService.getError_(err);
1145+
assert.strictEqual(error.message, errorMessage);
1146+
});
1147+
1148+
it('should return the original object for unknown errors', function() {
11371149
var error = GrpcService.getError_({ code: 9999 });
11381150

11391151
assert.strictEqual(error, null);

0 commit comments

Comments
 (0)