This library is deprecated. Use @ezez/errors instead.
Helper for creating Error subclass with bonus features. It fully works as expected with code transpiled to ES5 from ES6 code. It allows to pass custom data to errors and it contains features useful for logging/debugging.
Cleaner code.
instanceof
works as expected with multi level inheritance.Easy to use
null
or undefined
and it won't crash, so you don't need to care about
variable/property existence/initialization check.Enables better logging and bug tracking:
Full documentation of latest deprecated version is available here: documentation.
yarn add better-custom-error
or npm i better-custom-error --save
import { createError } from "better-custom-error";
// or const { createError } = require("better-custom-error");
const MyError = createError("MyError");
const AnotherError = createError("AnotherError", MyError); // it extends `Error` by default, but you can pass another error
const YetAnotherError = createError("YetAnotherError", Error, options);
For options
see: Options Usage.
Imporant: creating two errors with the same name will create two different errors references anyway! Export them and import where needed or make your errors global.
This library is basically all about creating new types on runtime.
TypeScript is static typechecker, therefore it doesn't play perfect with this, because every error has basically the
same type, optionally differentiating on details
object shape.
See documentation for more info.
better-custom-error
features will be available on native errors tooextend
method for easier extendingMIT
Generated using TypeDoc