node-request-retry icon indicating copy to clipboard operation
node-request-retry copied to clipboard

Custom retry strategy not retrying in certain cases

Open cwreid opened this issue 6 years ago • 1 comments

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: https://github.com/FGRibreau/node-request-retry/blob/e72edee56296b7163d18e061975c139f4caf1ff0/index.js#L133-L146

cwreid avatar Feb 21 '19 20:02 cwreid

Good catch, I will accept a PR with a non regression test :+1:

FGRibreau avatar Feb 21 '19 21:02 FGRibreau