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.

Better error message when xhr onerror

See original GitHub issue

i just found xhr onerror always reject error with same message, it’s very hard to find error cause.

xhr.onerror = function() {
    reject(new TypeError('Network request failed'))
}

simulator screen shot 2016 7 18 5 36 41

VS

simulator screen shot 2016 7 18 5 36 53

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:18
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
adamvosscommented, Oct 24, 2016

I have done some exploration of this. The conclusion I came to is there is no consistent way to provide more information. On some platforms, more information is available so an implementation that provides more information would just to code for various cases. Granted my exploration was against browsers that have a native fetch implementation so there would exist a very slight chance that the places that need polyfill do all behave in the same manner.

To summarize:

Firefox (49.0): The passed parameter is an Exception. The relevant information is on the name member. Chromimum (53.0.2785.143): The passed parameter is a ProgressEvent. The closest thing to relevant information says “error.” The XMLHttpRequest is accessible via the ProgressEvent but responseText is an empty string. The developer console does contain an error containing relevant information, but that is outside of the executing JavaScript. NativeScript (2.3.0): The passed parameter is some kind of Error. The relevant information is on the message member. React Native (inferred from @lloydsheng’s comments): Unknown if a parameter is passed but you can access the XMLHttpRequest via closure. Relevant information is on the responseText member.

According to the documentation for Internet Explorer 8, there are no parameter passed to the event handler, which near as I can tell matches the spec. However, implementation may differ from documentation.

5reactions
lloydshengcommented, Aug 3, 2016

@bergr01 The second error message was from iOS network framework. because the latest react native direct reference the fetch package. and i found this message available retrieval from xhr.responseText

Read more comments on GitHub >

github_iconTop Results From Across the Web

Catching XMLHttpRequest cross-domain errors - Stack Overflow
For CORS requests, the XmlHttpRequest's onError handler should fire. If you have access to the raw XmlHttpRequest object, try setting an event handler...
Read more >
XMLHttpRequest: error event - Web APIs | MDN
Use the event name in methods like addEventListener() , or set an event handler property. addEventListener('error', (event) => { }) onerror ...
Read more >
118096 - XHR error message is not sent to error handler.
Issue 118096: XHR error message is not sent to error handler. ... xhr.onerror = reject; xhr.onabort = reject; xhr.withCredentials = true;
Read more >
Using XMLHttpRequest to log JavaScript errors - The Art of Web
onerror function. If you return a value of true then only your function will be called and no message will be presented in...
Read more >
onerror Event - W3Schools
The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image). Tip: When used...
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