Does Fetch API throw errors when a request fails? Alternatively: How does Fetch API throw errors, and

18 Replies, 906 Views

So does Fetch API throw errors? Only if your request doesn’t even make it to the server.

For HTTP errors, you’re on your own. I usually do this:
```javascript
const res = await fetch(url);
if (!res.ok) throw new Error(`Failed with ${res.status}`);
```
Not ideal, but it works.

Messages In This Thread



Users browsing this thread: 1 Guest(s)