question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios doesn't resolve/reject on network level errors (i.e. onerror)

See original GitHub issue

I’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.

localhost 3000 2016-01-22 15-16-05

Any reason not to add a onerror handler? Happy to attempt a PR if not.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
nicklaw5commented, May 11, 2016

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?

1reaction
latentflipcommented, Jan 22, 2016

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.

localhost 3000 2016-01-22 16-13-12

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found