suhaotian / xior

A lite request lib based on fetch with plugin support and similar API to axios.
https://www.npmjs.com/package/xior
MIT License
114 stars 1 forks source link

Error handling #6

Closed fnoopv closed 4 months ago

fnoopv commented 4 months ago

A fetch() promise will reject with a TypeError when a network error is encountered or CORS is misconfigured on the server-side, other situations are not. is this library the same?

suhaotian commented 4 months ago

Yes! I did some test, actually same:

fetch('https://github.com')
  .then((res) => res.text())
  .catch((e) => {
    console.log('fetch:', e instanceof TypeError, e);
  });

const http = xior.create({});

http.get('https://github.com').catch((e) => {
  console.log('xior:', e instanceof TypeError, e);
});
image
fnoopv commented 4 months ago

ok, thanks