intermediate

Async errors and cancellation

Rejections, try/catch around await, Promise.all failure, AbortController, and stale results.

`try/catch` around `await` handles rejections inside async functions. Un-awaited Promises need `.catch()` or they become unhandled rejections.

`AbortController` provides cooperative cancellation — `fetch` and custom async work must check `signal.aborted`. Ignoring a stale HTTP response is not the same as cancelling the underlying request.

Retries on non-idempotent operations can duplicate side effects. `Promise.all` rejects on the first failure.

On interviews, explain the concept with a concrete example and name the runtime behavior interviewers probe.

Common pitfalls include mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus performance or safety versus convenience.

Checklist:

  • Catch awaited failures.
  • Handle un-awaited promises.
  • Use AbortController with cleanup.
  • Define retry idempotency.