QuizNot attempted
Spot the bug: error handling for two fetches
1–4 to choose, Enter to submit
Show answer & explanation
Correct answers:
- A 404 whose body is a JSON error object is treated as success and stored as table rows
- On failure the user just sees an empty table: no error message and no retry
- If either request fails, the result of the other one is lost too
fetchonly rejects on network failure, CORS or abort- a 404 or 500 resolves normally.
- Check
if (!res.ok) throw new Error("HTTP " + res.status)before.json(), keep the error in state and render a message with a retry. Promise.allrejects on the first failure, so usePromise.allSettled(or two independent requests) when one half is useful alone.- There is also no loading state.
- Not fetch rejects on non-2xx: it resolves with
ok: false - only parsing an HTML error page would throw, and then only by accident.