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

Add error code name to status error messages #126

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add original details string to errors, update tests
  • Loading branch information
murgatroid99 committed Jan 12, 2018
commit 01d66dd0b5c5be0a4d0230f67142d7d3c13ae5a1
3 changes: 2 additions & 1 deletion packages/grpc-native-core/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ var version = require('../package.json').version;
*/
function createStatusError(status) {
let statusName = _.invert(constants.status)[status.code];
let message = `${status.code} ${status.name}: ${status.details}`;
let message = `${status.code} ${statusName}: ${status.details}`;
let error = new Error(message);
error.code = status.code;
error.metadata = status.metadata;
error.details = status.details;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include error.metadata as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That is actually what I meant to write there. The details string is in the message. It probably doesn't need to be in a separate field too.

return error;
}

Expand Down
4 changes: 2 additions & 2 deletions test/api/credentials_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ describe('client credentials', function() {
client_options);
client.unary({}, function(err, data) {
assert(err);
assert.strictEqual(err.message,
assert.strictEqual(err.details,
'Getting metadata from plugin failed with error: ' +
'Authentication error');
assert.strictEqual(err.code, grpc.status.UNAUTHENTICATED);
Expand Down Expand Up @@ -369,7 +369,7 @@ describe('client credentials', function() {
client_options);
client.unary({}, function(err, data) {
assert(err);
assert.strictEqual(err.message,
assert.strictEqual(err.details,
'Getting metadata from plugin failed with error: ' +
'Authentication failure');
done();
Expand Down
8 changes: 4 additions & 4 deletions test/api/surface_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,15 @@ describe('Other conditions', function() {
client.unary({error: true}, function(err, data) {
assert(err);
assert.strictEqual(err.code, grpc.status.UNKNOWN);
assert.strictEqual(err.message, 'Requested error');
assert.strictEqual(err.details, 'Requested error');
done();
});
});
it('for a client stream call', function(done) {
var call = client.clientStream(function(err, data) {
assert(err);
assert.strictEqual(err.code, grpc.status.UNKNOWN);
assert.strictEqual(err.message, 'Requested error');
assert.strictEqual(err.details, 'Requested error');
done();
});
call.write({error: false});
Expand All @@ -1001,7 +1001,7 @@ describe('Other conditions', function() {
call.on('data', function(){});
call.on('error', function(error) {
assert.strictEqual(error.code, grpc.status.UNKNOWN);
assert.strictEqual(error.message, 'Requested error');
assert.strictEqual(error.details, 'Requested error');
done();
});
});
Expand All @@ -1013,7 +1013,7 @@ describe('Other conditions', function() {
call.on('data', function(){});
call.on('error', function(error) {
assert.strictEqual(error.code, grpc.status.UNKNOWN);
assert.strictEqual(error.message, 'Requested error');
assert.strictEqual(error.details, 'Requested error');
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/interop/interop_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function statusCodeAndMessage(client, done) {
client.unaryCall(arg, function(err, resp) {
assert(err);
assert.strictEqual(err.code, 2);
assert.strictEqual(err.message, 'test status message');
assert.strictEqual(err.details, 'test status message');
done();
});
var duplex = client.fullDuplexCall();
Expand Down