Make your own nested errors.
instanceof
inspect()
)fullStack(err)
make-error
npm install make-error-cause --save
import { BaseError, fullStack } from "make-error-cause";
class CustomError extends BaseError {
constructor(message, cause) {
super(message, cause);
}
}
const error = new Error("Boom!");
const customError = new CustomError("Another boom!", error);
console.log(customError); // Automatically prints full stack trace using `fullStack(this)`.
console.log(customError.cause); // Check causes via the `.cause` property.
console.log(customError instanceof Error); //=> true
Inspired by verror
, and others, but created lighter and without core dependencies for browser usage.
Other references:
Apache 2.0