Send requests to Dodi’s gudang and collect the stamps: 2xx success, 3xx moved, 4xx the asker’s fault, 5xx the gudang’s. 401 vs 403, what fetch does with a…
Why it matters
A wrong stamp (200 for an error, 200 when nothing was found) misleads clients, caches and search engines. And front-end code often forgets that fetch does not throw for 4xx/5xx, then wonders why the error is never caught. Knowing the stamp families means honest APIs and correct error handling.
The key idea
The first digit of an HTTP code decides its category
Common mistakes
fetch does not throw for 4xx/5xx Its promise still resolves. Check res.ok / res.status yourself (unlike axios, which throws).
Mixing up 401 and 403 401 = not authenticated yet (log in, show a ticket). 403 = known but without permission; logging in again does not change it.
Returning 200 for an error or missing data Clients, caches and crawlers are misled: res.ok is true, the error page gets cached and indexed. Use the right code (404, 400, 500), not "200 + an error in the body".
Try it in this playground
Send without a ticket, then with Rara’s 401: not known yet. 403: known, but not allowed. Two stamps in the 4xx column.
Use the old address /gudang-lama/42 fetch follows the 301 itself: res.status 200, res.redirected true.
Get a 201 stamp and a 204 stamp Not just 200: 201 for something just created (POST), 204 for success with no body (delete).
Ask for /api/rusak Stamp 500: fetch does not throw, the res.status >= 500 branch runs.