How do you handle errors in asynchronous code?
Answer out loud or in your head first, then compare.
Answer
When I use await, I wrap the operation in try/catch where I can sensibly decide what to do after an error. Not every error should be hidden. Sometimes you need to show the user a message, sometimes retry, and sometimes pass the error up.
It's important that the function actually waits for the operation. try { fetch(url); } won't catch a later rejection the way try { await fetch(url); } will. Also remember that fetch usually doesn't reject its Promise just because the server answered 404 or 500 — I check response.ok or the response status.
Why it matters: External APIs and AI models return errors regularly.
Possible follow-ups: Is it worth automatically retrying a missing-permissions error?
How did it go? Be honest — “Not yet” puts the question on your review list.
Further reading
- Node.js: The Event Loop(opens in a new tab)Docs; accessed 22.10.2026. Event loop phases, timers and differences between Node/libuv versions.