Networking & HTTP · Write code
fetch pitfalls and API error handling
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
This helper looks right but the caller always gets undefined. Find the bug. Then: how should a UI handle HTTP errors from fetch?
function getDogs() {
fetch('/api/dogs').then((r) => r.json());
}
getDogs().then(render); // TypeError
Then
Follow-ups the interviewer asks next
fetchresolves on 404/500, so checkres.ok.- Timeouts and abort.
- JSON parse errors and empty 204 bodies.
- Centralised API client with interceptors (or RTK Query
baseQuery).
The answer
What a strong answer covers
- Missing
return, so the function returnsundefined fetchrejects only on network failure or abort- Typed error objects; user-facing vs logged errors
The red pen
Common traps
Avoid:assuming fetch throws on 4xx.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.