retry-axios
retry-axios copied to clipboard
retry-axios doesn't work with latest axios release v1.1.3
I have a project that uses retry-axios
with axios v0.27.2
. It has been upgraded to axios v1.1.3
and the retries simply stopped working - it looks to me that the retries are somehow cached and the response is not being updated from the server. Downgrading to the previous v0.27.2
release solved the problem.
This is roughly how the code is structured:
import axios from 'axios'
import * as axiosRetry from 'retry-axios'
...
const retryConfig = {
retry: 10,
retryDelay: 2500,
httpMethodsToRetry: ['PATCH'],
statusCodesToRetry: [[404, 415]],
onRetryAttempt: (err) => {
const cfg = axiosRetry.getConfig(err)
helper.log(`retry update transaction date #${cfg.currentRetryAttempt}...`)
}
}
axiosRetry.attach()
...
patch(data) {
const options = {
method: 'patch',
raxConfig: retryConfig,
url: `theUrl`,
headers: {
'Content-Type': 'application/json'
},
data
}
return axios(options)
}
Possibly relates to https://github.com/JustinBeckwith/retry-axios/pull/201
Same issue here
@JustinBeckwith It would be nice to know if/when you are planning to fix this and/or if you have any hints for us of what this bug could be.
👋 no plan at the moment to fix this, but happy to review pull requests
+1
Seems known Axios bug, see axios/axios#5089.
The following line could fix the problem, which needs to placed before retrying the request.
//TODO: To be removed when https://github.com/axios/axios/issues/5089 gets closed.
err.config!.headers = JSON.parse(JSON.stringify(err.config?.headers || {}))
As client/user of retry-axios
, you could extend your onRetryAttempt
callback of your concrete RetryConfig
.
const retryConfig: RetryConfig = {
retry: 3,
retryDelay: 1000,
httpMethodsToRetry: ['GET'],
statusCodesToRetry: [[404,500]],
onRetryAttempt: err => {
//TODO: To be removed when https://github.com/axios/axios/issues/5089 gets closed.
err.config!.headers = JSON.parse(JSON.stringify(err.config?.headers || {}))
}
};