Skip to content

Custom retry strategy not retrying in certain cases #98

@cwreid

Description

@cwreid

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:

node-request-retry/index.js

Lines 133 to 146 in e72edee

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);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions