Skip to content

Commit eeb06e7

Browse files
committed
renamed getError_ to getStatus_
1 parent 46f6016 commit eeb06e7

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

lib/common/grpc-service.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ GrpcService.prototype.request = function(protoOpts, reqOpts, callback) {
244244

245245
service[protoOpts.method](reqOpts, grpcOpts, function(err, resp) {
246246
if (err) {
247-
respError = GrpcService.getError_(err);
247+
respError = GrpcService.getStatus_(err);
248248

249249
if (respError) {
250250
onResponse(null, respError);
@@ -326,7 +326,7 @@ GrpcService.prototype.requestStream = function(protoOpts, reqOpts) {
326326
request: function() {
327327
return service[protoOpts.method](reqOpts, grpcOpts)
328328
.on('status', function(status) {
329-
var grcpStatus = GrpcService.getError_(status);
329+
var grcpStatus = GrpcService.getStatus_(status);
330330

331331
this.emit('response', grcpStatus || status);
332332
});
@@ -335,7 +335,7 @@ GrpcService.prototype.requestStream = function(protoOpts, reqOpts) {
335335

336336
return retryRequest(null, retryOpts)
337337
.on('error', function(err) {
338-
var grpcError = GrpcService.getError_(err);
338+
var grpcError = GrpcService.getStatus_(err);
339339

340340
stream.destroy(grpcError || err);
341341
})
@@ -447,22 +447,22 @@ GrpcService.createDeadline_ = function(timeout) {
447447
};
448448

449449
/**
450-
* Checks for a grpc error code and extends the Error object with additional
450+
* Checks for a grpc status code and extends the status object with additional
451451
* information.
452452
*
453453
* @private
454454
*
455-
* @param {error} err - The original request error.
456-
* @return {error|null}
455+
* @param {error|object} status - The original status object.
456+
* @return {error|object|null}
457457
*/
458-
GrpcService.getError_ = function(err) {
459-
if (err && GRPC_ERROR_CODE_TO_HTTP[err.code]) {
460-
var defaultErrorDetails = GRPC_ERROR_CODE_TO_HTTP[err.code];
461-
var errorObj = is.error(err) ? new Error() : {};
462-
463-
return extend(true, errorObj, err, {
464-
code: defaultErrorDetails.code,
465-
message: err.message || defaultErrorDetails.message
458+
GrpcService.getStatus_ = function(status) {
459+
if (status && GRPC_ERROR_CODE_TO_HTTP[status.code]) {
460+
var defaultStatusDetails = GRPC_ERROR_CODE_TO_HTTP[status.code];
461+
var statusObj = is.error(status) ? new Error() : {};
462+
463+
return extend(true, statusObj, status, {
464+
code: defaultStatusDetails.code,
465+
message: status.message || defaultStatusDetails.message
466466
});
467467
}
468468
return null;

test/common/grpc-service.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,13 +1120,13 @@ describe('GrpcService', function() {
11201120
});
11211121
});
11221122

1123-
describe('getError_', function() {
1124-
it('should retrieve the HTTP error from the gRPC error map', function() {
1123+
describe('getStatus_', function() {
1124+
it('should retrieve the HTTP code from the gRPC error map', function() {
11251125
var errorMap = GrpcService.GRPC_ERROR_CODE_TO_HTTP;
11261126
var codes = Object.keys(errorMap);
11271127

11281128
codes.forEach(function(code) {
1129-
var error = GrpcService.getError_({ code: code });
1129+
var error = GrpcService.getStatus_({ code: code });
11301130

11311131
assert.notStrictEqual(error, errorMap[code]);
11321132
assert.deepEqual(error, errorMap[code]);
@@ -1141,12 +1141,12 @@ describe('GrpcService', function() {
11411141
message: errorMessage
11421142
};
11431143

1144-
var error = GrpcService.getError_(err);
1144+
var error = GrpcService.getStatus_(err);
11451145
assert.strictEqual(error.message, errorMessage);
11461146
});
11471147

1148-
it('should return the original object for unknown errors', function() {
1149-
var error = GrpcService.getError_({ code: 9999 });
1148+
it('should return null for unknown errors', function() {
1149+
var error = GrpcService.getStatus_({ code: 9999 });
11501150

11511151
assert.strictEqual(error, null);
11521152
});

0 commit comments

Comments
 (0)