diff --git a/CHANGELOG.md b/CHANGELOG.md index 428870a9..bc18b6e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # Changelog +## Next Release + +- Fixed an issue where an error is thrown during a retry when a response is not returned by the previous call (#476). + ## 1.31.0 [2020-02-13] -- Fix Authentication Request Retries +- Fixed Authentication Request Retries - Added marker-based paging for users endpoints - Added `getNextMarker()` to PagingIterator to get the next marker diff --git a/lib/api-request.js b/lib/api-request.js index fccb2948..8782b07a 100644 --- a/lib/api-request.js +++ b/lib/api-request.js @@ -224,7 +224,7 @@ APIRequest.prototype.getResponseStream = function() { * @private */ APIRequest.prototype._handleResponse = function(err, response) { - + // Clean sensitive headers here to prevent the user from accidentily using/logging them in prod cleanSensitiveHeaders(this.request); @@ -305,7 +305,7 @@ APIRequest.prototype._retry = function(err) { this._finish(err); return; } - } else if (err.response.hasOwnProperty('headers') && err.response.headers.hasOwnProperty('retry-after')) { + } else if (err.hasOwnProperty('response') && err.response.hasOwnProperty('headers') && err.response.headers.hasOwnProperty('retry-after')) { retryTimeout = err.response.headers['retry-after'] * 1000; } else { retryTimeout = getRetryTimeout(this.numRetries, this.config.retryIntervalMS); diff --git a/lib/token-manager.js b/lib/token-manager.js index 48082bf2..ae48f061 100644 --- a/lib/token-manager.js +++ b/lib/token-manager.js @@ -404,7 +404,7 @@ TokenManager.prototype = { } throw error; } - } else if (error.response.headers.hasOwnProperty('retry-after')) { + } else if (error.hasOwnProperty('response') && error.response.hasOwnProperty('headers') && error.response.headers.hasOwnProperty('retry-after')) { retryTimeout = error.response.headers['retry-after'] * 1000; } else { retryTimeout = getRetryTimeout(numRetries, this.config.retryIntervalMS);