Comments (18)
As stated in a PR that was adding that as a configuration (which was rejected as we're trying to keep the API minimal), you can still retry timeout errors using the built-in functions with way:
retryCondition: (error) => {
return axiosRetry.isNetworkOrIdempotentRequestError(error)
|| error.code === 'ECONNABORTED';
}
from axios-retry.
Thanks @erdii - that issue doesn't make any sense at all. Timeouts should definitely be retried. For us at least, it's the only reason we want to retry!
from axios-retry.
A new option retryCondition
(Default: error => !error.response) has been added.
This issue can be closed now, am I right?
Thank you @rubennorte!
Edit: I still cannot use the retryCondition function to retry ECONNABORTED requests because of this guy here:
const shouldRetry = retryCondition(error)
&& error.code !== 'ECONNABORTED'
&& config.retryCount < retries
&& isRetryAllowed(error);
shouldn't this be:
const shouldRetry = retryCondition(error)
&& config.retryCount < retries;
and the default retryCondition
something like error => !error.response && isRetryAllowed(error) && error.code !== 'ECONNABORTED'
?
EDIT2: add forgotten ECONNABORTED handling
EDIT3: I'd happily create a pull request containing the code changes and tests if you approve this change
from axios-retry.
Add a new config? retryOnTimeout, set default to false.
In someway, timeout means I wants to cancel this request and retry.
from axios-retry.
We're going to make some changes in the library soon, including one to solve this issue. What do you think about:
import axios from 'axios';
import axiosRetry from 'axios-retry';
axiosRetry(axios, {
retryCondition: axiosRetry.isNetworkError, // default
retryCondition: axiosRetry.isAnyError // alternative
retryCondition: (response) => { // custom
return axiosRetry.isNetworkError(response) || response.config.method === 'GET'
}
});
from axios-retry.
Seems reasonable to me @rubennorte. I'd also recommend adding some sort of retryDelay
parameter which can be a simple number, or a function which is passed the last error, and the current retry count, allowing for exponential decays, thus:
// with retries: 7, retries 7 times with a 1 second gap.
retryDelay: 1000
// for timeouts, wait longer before retrying. For all other errors, just 1 second.
retryDelay: (error) => { return (error.message === 'ETIMEDOUT') ? 60000 : 1000 }
// linear decay
retryDelay: (error, count) => { return count * 1000 }
// exponential decay
retryDelay: (error, count) => { return (count * count) * 1000 }
Maybe this is a new feature rather than an addition to this one, but it's something got
has built in - and ultimately was our reason for switching to it. We really want our payloads to go through, and our providers (banks!) are super-flaky sometimes.
from axios-retry.
Hi @rubennorte,
I check you latest version, but this line still prevent it retry on timeout.
error.code !== 'ECONNABORTED'
I think put it into the default retryCondition is a better idea, so anyone doesn't need it can override it. I can send a PR if you need.
export function isNetworkError(error) {
return !error.response && error.code !== 'ECONNABORTED';
}
Thanks for making this lib, I use it in my projects, but I have to make a copy and remove that line every time., it's really inconvenient.
from axios-retry.
Weird, ive implemented the override via retryCondition() with return true and my retries dont trigger.
RESOLVED:
full config.. im using nestjs so access to axios is through the httpService reference and configuring a http agent timeout...
After some debugging I realized that for this to work, shouldRetryOnTimeout
need to be set to true, otherwise the timeout which is inherited by the http module agent configuration ends up timing out and the retry condition never triggers.
hopefully this will help someone else!
axiosRetry(httpService.axiosRef, {
retries: 3,
retryDelay: () => 100, // in milliseconds
shouldResetTimeout: true,
retryCondition: (error: AxiosError) => {
return (
isNetworkOrIdempotentRequestError(error) ||
error.code === "ECONNABORTED"
);
},
...
}
from axios-retry.
I'm a bit busy right now - but I have school next week so I'll have plenty of time to implement it and create a pull request. Is this ok? @Lxxyx @antony ?
@rubennorte are you willing to accept my pr when i provide test coverage and doc updates? :)
from axios-retry.
I think this is because of #5
from axios-retry.
I'm testing the lib right now and it seems that it doesn't retry if you disconnect from the network (on mobile) at all.
maybe we should give tomaash/axios-status a try. (even though it changes the request interface)
from axios-retry.
I've had to revert back to got
right now because this transition is taking too long. next time I venture into it I will look at axios-status so thanks for that!
from axios-retry.
The error that's being specifically ignored in the code is ECONNABORTED, which means that the program itself cancelled the request due to a specific cancellation or a timeout. What use case do you have that you need to retry those? Why don't you simply increment the timeout?
Retrying on timeout could make requests too slow, as if something goes wrong you'll be paying the cost of the timeout for each call.
from axios-retry.
What we do is talk to a variety of different bank APIs to get loans. Some of these APIs can take upto 2 minutes to reply, and often they will take longer. What we do is set our timeout to 2 minutes, and if they take longer, we just retry the request. We do this up to 5 times before giving up.
With got (native)/request (requestretry) this is no problem, but I'd like to switch to axios - however this ECONNABORTED check prevents me from doing so.
from axios-retry.
@erdii idea is great. Can you change the code? @antony
from axios-retry.
Yes @erdii - this is exactly what I was suggesting. To be able to configure the retry conditions in this way is absolutely critical.
from axios-retry.
I have implemented the changes, tests, and documentation at erdii@25faf8f. Creating a pull request now.
from axios-retry.
Still I can't use the lib implementation overall.
isNetworkError
, isSafeRequestError
and isIdempotentRequestError
still checks for :
error.code !== 'ECONNABORTED'
This error code received when defining axios a timeout, and it has passed.
This is like the most wanted scenario to retry.
So currently I still cant use this function implementation.
Maybe you could have a configuration option to decide whether or not to check for ECONNABORTED
?
from axios-retry.
Related Issues (20)
- Create a Security Policy HOT 1
- Success axios interceptors fired multiple times HOT 7
- [TypeScript]Unable to import names HOT 2
- Inconsistent Behavior of `isNetworkOrIdempotentRequestError` Function HOT 1
- Requiring cjs is broken since the last version (4.0.0)
- TypeError: axiosRetry is not a function in v4.0.0 HOT 11
- Module parse failed: Unexpected token (24:20) HOT 1
- Retry not working on HTTP 502 HOT 3
- How to handle errors HOT 2
- Combining `axios-retry` with other interceptors HOT 1
- [Feature request]onMaxRetryTimesExceeded to allow user to emit a custom error after retries done
- Provide option to trigger retry from successful (200) response in Axios's response interceptors HOT 4
- Do we still need `fixConfig`?
- Attach a unique id with request
- Axios-retry swallows the error response HOT 3
- Exponential delay has unnecessary final sleep HOT 2
- Introduce "axiosRetry.linearDelay"
- FormData not work HOT 1
- Abort during retry causes uncaught exception HOT 3
- Duplicated URL params HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios-retry.