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

provide better error messaging - fixes #286 #303

Merged
merged 2 commits into from
Nov 17, 2014
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
9 changes: 7 additions & 2 deletions lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,14 @@ function makeAuthorizedRequest(config) {
if (err.code === 401 &&
++tokenRefreshAttempts <= MAX_TOKEN_REFRESH_ATTEMPTS) {
authorize(reqOpts, onAuthorizedRequest);
} else {
(callback.onAuthorized || callback)(err);
return;
}

if (err.message === 'SignFinal error') {
err.message = 'There was an error with your private key.';

This comment was marked as spam.

This comment was marked as spam.

}

(callback.onAuthorized || callback)(err);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"dependencies": {
"duplexify": "^3.1.2",
"extend": "^1.3.0",
"google-service-account": "^1.0.0",
"google-service-account": "^1.0.3",

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

"mime": "^1.2.11",
"node-uuid": "^1.4.1",
"protobufjs": "^3.4.0",
Expand Down
23 changes: 18 additions & 5 deletions test/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

var assert = require('assert');
var duplexify = require('duplexify');
var gsa = require('google-service-account');
var request = require('request');

var util = require('sandboxed-module')
Expand All @@ -31,20 +32,17 @@ var util = require('sandboxed-module')
});

var gsa_Override;

function fakeGsa() {
var args = [].slice.apply(arguments);
var results = (gsa_Override || util.noop).apply(null, args);
var results = (gsa_Override || gsa).apply(null, args);
gsa_Override = null;
return results || { getCredentials: util.noop };
}

var request_Cached = request;
var request_Override;

function fakeRequest() {
var args = [].slice.apply(arguments);
var results = (request_Override || request_Cached).apply(null, args);
var results = (request_Override || request).apply(null, args);
request_Override = null;
return results;
}
Expand Down Expand Up @@ -322,6 +320,21 @@ describe('common/util', function() {
});
});

it('should handle malformed key response', function(done) {
var makeRequest = util.makeAuthorizedRequest({
credentials: {
client_email: 'invalid@email',
private_key: 'invalid-key'
}
});

makeRequest({}, function (err) {
var errorMessage = 'There was an error with your private key.';
assert.equal(err.message, errorMessage);
done();
});
});

it('should try to reconnect if token invalid', function(done) {
var attempts = 0;
var expectedAttempts = 2;
Expand Down