Better error message when xhr onerror
See original GitHub issuei 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'))
}
VS
Issue Analytics
- State:
- Created 7 years ago
- Reactions:18
- Comments:11 (1 by maintainers)
Top 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 >
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 Free
Top 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
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 thename
member. Chromimum (53.0.2785.143): The passed parameter is aProgressEvent
. The closest thing to relevant information says “error.” TheXMLHttpRequest
is accessible via theProgressEvent
butresponseText
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 themessage
member. React Native (inferred from @lloydsheng’s comments): Unknown if a parameter is passed but you can access theXMLHttpRequest
via closure. Relevant information is on theresponseText
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.
@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