mirror of
https://github.com/HackPlan/google-auth-library-nodejs.git
synced 2026-04-28 19:55:40 +08:00
Added test for OAuth2Client#request retry, fixed implementation
This commit is contained in:
@@ -344,12 +344,17 @@ OAuth2Client.prototype.request = function(opts, callback) {
|
||||
// Hook the callback routine to call the _postRequest method.
|
||||
var postRequestCb = function(err, body, resp) {
|
||||
// Automatically retry 401 and 403 responses
|
||||
if (retry && err && (err.code == 401 || err.code == 403)) {
|
||||
// if err is set, then getting credentials failed, and retrying won't help
|
||||
if (retry && !err && resp &&
|
||||
(resp.statusCode == 401 || resp.statusCode == 403)) {
|
||||
/* It only makes sense to retry once, because the retry is intended to
|
||||
* handle expiration-related failures. If refreshing the token does not
|
||||
* fix the failure, then refreshing again probably won't help */
|
||||
retry = false;
|
||||
that.getRequestMetadata(unusedUri, authCb);
|
||||
// Force token refresh
|
||||
that.refreshAccessToken(function() {
|
||||
that.getRequestMetadata(unusedUri, authCb);
|
||||
});
|
||||
} else {
|
||||
that._postRequest(err, body, resp, callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user