Error cause: Chaining the Real Culprit

An error climbs Gang Kenari as an envelope from house to house: a catch with { cause } puts the old one inside a new envelope. What if one catch forgets…

Why it matters

In a real app, a network error passes through many layers (fetch, service, handler, UI). If every layer throws a new message without cause, the production log only says "Formulir gagal dikirim", and the real HTTP 500 is gone. { cause } (ES2022) lets one catch at the top trace all the way down.

The key idea

{ cause } keeps the old error inside the new one

Common mistakes

Try it in this playground