JavaScript Error.prototype.cause Property
The cause property of an Error records the original error that led to it, so wrapped errors keep their underlying reason.
Description
The cause property holds the underlying reason for an error, set with the cause option: new Error(message, { cause: err }). It lets you throw a higher-level, more meaningful error without losing the original details, which consoles and logging tools can show together.
The cause can be any value, not only an error, so you can attach extra context such as the failing request. Browser consoles typically show the cause chain when logging the error, which makes tracking down the original problem much easier.
Before cause was added in 2021, libraries used their own property names, such as originalError, for the same purpose. The cause option works with all built-in error types and with subclasses that pass their options to super().
Syntax
error.causeValue
The value given as the cause option, usually another error.
Example
Browser Support
The following information will show you the current browser support for the Error.prototype.cause property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





