suhaotian / xior

A lite request lib based on fetch with plugin support and similar API to axios.
https://suhaotian.github.io/xior/
MIT License
193 stars 4 forks source link

Error handling #6

Closed fnoopv closed 8 months ago

fnoopv commented 8 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 8 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 8 months ago

ok, thanks