Axios users

Posted Jan 29, 2023, 5:35 AM UTC

Posted Jan 29, 2023, 5:35 AM UTC
It'd be nice if fetch actually threw errors when errors happen.
Does it not throw error? I’m quite sure it does
I don't think it actually throws them. It just returns the error as part of the response payload and then you can handle it however you like.
You mean HTTP status codes? From the point of view of the HTTP protocol the request completed successfully, and it's up to the application to interpret the status code. The behavior of Axios is rather weird in that aspect.
It's been a while since I've used fetch, but I'm pretty sure it has a number of fields you can use. It has an 'ok' property which will be true on any 200 response. It has the actual status code, and I think it has some other properties where it exposes some generic error messages as well. Depending on the result you may still need to parse the body to see what the server's actual error message was.
And some typing would be nice 🤠
with fetch, there's always a catch
axios bad fetch good
Thank you for coming to my TED talk.
This meme is sooo axios
in my 3 years of experience, I hardly find any different in them
Really? For one, fetch is included in node >= 18, while axios must be installed separately. In fetch, the body of a response is a promise, which means retrieving the json/text must be awaited, while in axios it’s automatically transformed. Other than that, in general fetch is fairly straightforward but has some limited (or at least more verbose) functionality. If you have some special use cases such as http interception and request timeouts, axios is better.
Really? Just send over some binary data
got gang rise up
This is an underrated usage of that meme, nice job