Skip to main content

Demo 10

Promise rejection

Rejected promises skip success handlers and go to rejection handlers.

fully simulatedcurated scenariodoes not execute real code
Short answer

The key output order is bad. A rejection bypasses `.then` success callbacks until a rejection handler catches it.

Real-world bug this helps solve

A later .then receives the wrong value, an error appears in a surprising place, or a batch fails differently than expected. Centralized `.catch` handlers are common for fetch and async workflows.

Common wrong assumption

Expecting every `.then` in a chain to run.

Fix direction

Return or await the promise chain so values and failures move through the flow intentionally.

Fixed code pattern
return doWork()
  .then((value) => nextStep(value))
  .catch(handleError);
Visual proof

The console lane proves the visible order: bad. The active line and queues show why source order changed.

How to verify in a real app

Write a focused unit test that asserts the resolved value or rejected path, then verify every branch returns or awaits its work.

Share
Loading visual timeline...

Related cases

Continue with nearby confusion while the mental model is fresh.

Recommended next

Was this clear?

This stays local for now. It helps you track where the product still needs sharper cases.

Send detail