js-standard-errors
This package contains a number of errors that I thought were missing in vanilla Javascript. There are currently just two errors in this package, but I plan to add more errors when I need one in a project.
All errors also have a unique code
attribute to conform to the direction that the core Node.JS-team is taking
with their errors. They also have a name
attribute that matches their constructor name.
For example, new NotImplementedError()
results in an error with the following attributes:
Included errors
- ArgumentError (
ERR_INVALID_ARGUMENT
) - NotImplementedError (
ERR_NOT_IMPLEMENTED
)
Implementing custom errors
The standard Javascript Error
implementation is not that easy to extend using ES6 classes. That is why this package also exposes ExtendableError
: an easy to extend ES6 class that wraps Error
.
const ExtendableError = ; { supermessage || 'There was an error' 'ERR_CUSTOM_ERROR' options; } moduleexports = ArgumentError;