Yeah, fetch is kinda weird like that. It *does* throw errors for network failures, but HTTP errors like 404 or 500? Nope, those still resolve.
I usually wrap fetch in a helper function that checks `response.ok` and throws if it’s false. Saves me from writing the same checks over and over.
Here’s a quick example:
```javascript
async function fetchWithThrow(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
return res.json();
}
```
Makes life easier.
I usually wrap fetch in a helper function that checks `response.ok` and throws if it’s false. Saves me from writing the same checks over and over.
Here’s a quick example:
```javascript
async function fetchWithThrow(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
return res.json();
}
```
Makes life easier.
