Axios not failing on chrome "canceled request".
See original GitHub issueSummary
Google Chrome may cancel requests sometimes. Axios does not seem to throw an error when this happens.
Context
- axios version: 0.17.1
- Environment: Electron / Chrome / Chromium
For more details about what can cause this situation, here is a stackoverflow link "What does status=canceled for a resource mean in Chrome Developer Tools? ". This is also valid in Chromium (Electron apps).
I was expecting axios to fail and throw an error when this happens. But this code does not work:
refreshData () {
this.isFetching = true
this.fetchingError = false
return this.fetchData()
.then(() => {
this.set('lastUpdated', new Date())
})
.catch((err) => {
this.set('fetchingError', true)
})
.finally(() => {
this.set('isFetching', false)
})
}
Nor catch
, nor finally
run.
Is this an expected behaviour?
(In case you don’t know about: finally)
Issue Analytics
- State:
- Created 6 years ago
- Comments:24
Top Results From Across the Web
How to catch status = cancelled in axios? - Stack Overflow
This happens because you set the timeout in axios. Of course when the request times out, axios cancels the request. By default timeout...
Read more >Axios ajax call not working working on chrome but working safari
i'm struggling with this issue since a couple of hours now, on my app i'm requesting data from DB using axios ajax function....
Read more >HTTP status and error codes for JSON | Cloud Storage
The resumable upload was cancelled at the client's request prior to completion. This error has no response body. 500—Internal Server Error. Reason, Description ......
Read more >Cancel all axios requests in React's componentWillUnmount ...
The single action of cancelling API request when it is no longer needed ... React alerts us to this problem by outputting these...
Read more >axios - npm
Requests can be made by passing the relevant config to axios . ... or to cancel the request by throwing an error //...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it helped me -> event.preventDefault();
Found the solution guys! @AoDev
Axios documentation has a timeout of 1000 like:
axios.create({ ..., timeout: 1000, ... })
I increased the timeout to 5000. I think Axios documentation needs to be updated to change the timeout to a higher number to prevent newcomers to go crazy trying to figure out what’s going on.
I hope this solutions helps!