Won't retry more than once
See original GitHub issueEDIT: I swapped retry-axios for axios-retry @ https://github.com/softonic/axios-retry , using the same logical flow and it works fine with proper repeats. What’s so different about retry-axios’ implementation?
Hello.
I’ve been trying to get this wonderful interceptor all day but I just can’t get it to work with my React app.
I have the following code.
export default{
get(url, conf = {}) {
const client = getClient();
client.defaults.raxConfig = {
retry: 5,
instance: client,
noResponseRetries: 5,
statusCodesToRetry: [[100, 199], [400, 429],[500, 599]],
onRetryAttempt: (err) => {
const cfg = rax.getConfig(err);
console.log(`Retry attempt #${cfg.currentRetryAttempt}`);
}
}
const interceptorId = rax.attach(client)
return client.get(url, conf)
}
}
Basically another apiCall.js file calls the exported function, it creates an axios instance with some basic options via getClient(), attaches the raxConfig, attaches rax itself and then returns the get request.
The apiCall.js file then resolves the promises via .then() and .catch().
The problem im experiencing is no matter what I do retry-axios only retries once.
I know it uses the config because it properly reacts to changes in statusCodesToRetry, but doesn’t do anything after the first retry.
I’m really desperate here and any help is appreciated. Thank you.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Had a similar issue, this was due to the use of axios defaults which is copied by reference, not cloned to each request. This meant the number of current retries stored in the config by the request error handler is global, leading to effectively 1 set of retries.
This can be fixed using a request interceptor to set the config instead such as the following (typescript):
usage:
relates to #1
Okay, my problem was that in the config, httpMethodsToRetry didn’t include the POST method by default.