Axios doesn't resolve/reject on network level errors (i.e. onerror)
See original GitHub issueI’ve noticed that on current chrome (unsure how other browsers treat this) axios doesn’t resolve or reject if I forget to start my api server. I believe it’s because at the network level, onload never gets called on a request, but onerror does instead, and looking at https://github.com/mzabriskie/axios/blob/master/lib/adapters/xhr.js we don’t handle onerror at all.
Any reason not to add a onerror
handler? Happy to attempt a PR if not.
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (11 by maintainers)
Top Results From Across the Web
NETWORK ERROR does not get resolved by axios [duplicate]
Server being offline is not an error really. In fact, you shouldn't rely on any HTTP tool (be it axios or native fetch...
Read more >rox-browser.min.js.map - UNPKG
setLevel('error'); \n }\n};\n\n\nexport default logger\n\n\n\n// WEBPACK FOOTER ... };\n\n // Handle low level network errors\n request.onerror = function ...
Read more >axios example - Code Playground - JSFiddle
var root = 'https://53f7877f.ngrok.io/ping'. 2. . 3. // Make a GET request. 4. . 5. axios.get(root). 6 .then((data) => {. 7. console.log('data', data)....
Read more >axioserror request failed with status code 500 react native
I am getting two errors front end errorm AxiosError: Request failed with status code 500 ... TypeError: Network request failed at XMLHttpRequest.xhr.onerror ......
Read more >If Backendserver Is Down Then How To Handle In Reactjs With Axios
Axios doesn't resolve/reject on network level errors i.e. onerror #204 Set a code/status for Network Error #383. Closed. @axios.
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
I’m receiving “Network error” but server is responding with “500 Internal Server Error”.
Would be great if this error response could be more explicit for better application handling. Is this possible?
So it looks like onerror doesn’t actually return an error, but a progress event. At least in the case of
http://localhost:5000
when the api isn’t actually running.Throwing that event I don’t think makes sense since it’s not even an error object. According to: http://stackoverflow.com/questions/4844643/is-it-possible-to-trap-cors-errors in at least the situation of cors errors, the actual error is not available to your JS code (just gets logged to the console).
So I guess we’re back to: either rejecting with a 0 status, or just throwing something like
new Error('Unknown XHR error')
thoughts?