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

[improvement] allow retryStrategy to be async

Open Hoya opened this issue 6 years ago • 1 comments

If the function for retryStrategy is an async function the request will continue to retry even when the request has been successfully executed.

I'm trying to update the proxy settings on retry and I need to pull a new proxy from an API within the retryStrategy function.

Hoya avatar Jul 15 '19 06:07 Hoya

Maybe a backward-compatible change to the retryStrategy API could be:

function myRetryStrategy(err, response, body, options, cb){
  // retry the request if we had an error or if the response was a 'Bad Gateway'
 cb(!!err || response.statusCode === 502);
}

and then on request-retry-side we wouls have to check for myRetryStrategy.length in order to understand if the function is sync or async :)

I will accept a PR for that :)

FGRibreau avatar Jul 22 '19 06:07 FGRibreau