better-custom-error
Helper for creating Error subclass with bonus features.
It fully works with Babel (as opposed to native ES6 class
), allows to pass custom data to errors and it contains
features useful for logging/debugging.
Reasons to use
Usage
Full documentation available here: documentation.
yarn add better-custom-error
or npm i better-custom-error --save
import createError from "better-custom-error";
const MyError = createError("MyError");
const AnotherError = createError("AnotherError", MyError);
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.
TODO
- Further memory optimization:
- create and extend one Custom Error instance
- use getters to delay some calculations from error creation to actual read place
- Ability to override Error prototype so some
better-custom-error
features will be available on native errors too extend
method for easier extending
License
MIT