lquixada / cross-fetch

Universal WHATWG Fetch API for Node, Browsers and React Native.
MIT License
1.67k stars 104 forks source link

Error message given by `fetch` for `xhr.onerror` is not useful #133

Closed FrozenPyrozen closed 2 years ago

FrozenPyrozen commented 2 years ago

Main problem: The function assigned to xhr.onerror does not propagate helpful information concerning the error that occurred, instead only "Network request failed" is presented.

For example I've got an error

image

On my fetch error handling I've got error: TypeError: Network request failed

image

But I need to see all error info like ...has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

How to fix?

In browser-polyfill.js

image

We should change xhr.onerror to:

image

I could open the PR, but I can't see browser-polyfill.js here

image
FrozenPyrozen commented 2 years ago

I would close it, because it's not possible to catch CORS error with xhr(