Video tutorialTrack course · freeCodeCamp
Speed
Transcript & captions
4/4
jsjs
const res = await fetch('https://api.example.com/users');
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();Try it yourself
fetch only rejects on network errors — a 404 or 500 still resolves, so always check res.ok.
Knowledge check
0/1 answeredDoes fetch throw on a 500 response?