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

Custom retry strategy not retrying in certain cases #98

Open
cwreid opened this issue Feb 21, 2019 · 1 comment
Open

Custom retry strategy not retrying in certain cases #98

cwreid opened this issue Feb 21, 2019 · 1 comment

Comments

@cwreid
Copy link

cwreid commented Feb 21, 2019

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

@FGRibreau
Copy link
Owner

Good catch, I will accept a PR with a non regression test 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants