Following the custom retry strategy example below (from the readme):
/**
* @param {Null | Object} err
* @param {Object} response
* @param {Object} body
* @param {Object} options copy
* @return {Boolean} true if the request should be retried
*/
function myRetryStrategy(err, response, body, options){
// retry the request if we had an error or if the response was a 'Bad Gateway'
return err || response.statusCode === 502;
}
When err is an object and this function returns that object, mustRetry becomes undefined bypassing the desired retry attempt based on the logic here because mustRetry.mustRetry is not a thing in this scenario:
|
var mustRetry = this.retryStrategy(err, response, body, _.cloneDeep(this.options)); |
|
if (_.isObject(mustRetry)) { |
|
if (_.isObject(mustRetry.options)) { |
|
this.options = mustRetry.options; //if retryStrategy supposes different request options for retry |
|
} |
|
mustRetry = mustRetry.mustRetry; |
|
} |
|
|
|
if (mustRetry && this.maxAttempts > 0) { |
|
this._timeout = setTimeout(this._tryUntilFail.bind(this), this.delayStrategy.call(this, err, response, body)); |
|
return; |
|
} |
|
|
|
this.reply(err, response, body); |
Following the custom retry strategy example below (from the readme):
When
erris an object and this function returns that object,mustRetrybecomesundefinedbypassing the desired retry attempt based on the logic here becausemustRetry.mustRetryis not a thing in this scenario:node-request-retry/index.js
Lines 133 to 146 in e72edee