diff options
author | murgatroid99 <mlumish@google.com> | 2016-08-02 13:07:35 -0700 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2016-08-02 13:07:35 -0700 |
commit | 2db3d9926997ba6a94c9d50bdf5ff4c75e7680e3 (patch) | |
tree | 8f4f9c51c15824ead3b4e08adc2d878625d085c1 /src | |
parent | 9fa684fa0d0527b9a9271681940d8f99b9c2787c (diff) |
Fix error handling authentication errors with non-numeric error codes
Diffstat (limited to 'src')
-rw-r--r-- | src/node/src/credentials.js | 4 | ||||
-rw-r--r-- | src/node/test/credentials_test.js | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/node/src/credentials.js b/src/node/src/credentials.js index 043df06a66..51ff1da01e 100644 --- a/src/node/src/credentials.js +++ b/src/node/src/credentials.js @@ -71,6 +71,8 @@ var Metadata = require('./metadata.js'); var common = require('./common.js'); +var _ = require('lodash'); + /** * Create an SSL Credentials object. If using a client-side certificate, both * the second and third arguments must be passed. @@ -99,7 +101,7 @@ exports.createFromMetadataGenerator = function(metadata_generator) { var message = ''; if (error) { message = error.message; - if (error.hasOwnProperty('code')) { + if (error.hasOwnProperty('code') && _.isFinite(error.code)) { code = error.code; } else { code = grpc.status.UNAUTHENTICATED; diff --git a/src/node/test/credentials_test.js b/src/node/test/credentials_test.js index 0a21572582..305843f665 100644 --- a/src/node/test/credentials_test.js +++ b/src/node/test/credentials_test.js @@ -71,7 +71,10 @@ var fakeSuccessfulGoogleCredentials = { var fakeFailingGoogleCredentials = { getRequestMetadata: function(service_url, callback) { setTimeout(function() { - callback(new Error('Authentication failure')); + // Google credentials currently adds string error codes to auth errors + var error = new Error('Authentication failure'); + error.code = 'ENOENT'; + callback(error); }, 0); } }; |