node-request-retry
node-request-retry copied to clipboard
[improvement] allow retryStrategy to be async
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.
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 :)