0.1.0-beta.3 • Published 11 months ago
@alliage/error-handler v0.1.0-beta.3
Alliage Error Handler
Module allowing to display exceptions gracefully.
Installation
yarn add @alliage/error-handler
With npm
npm install @alliage/error-handler
Registration
If you have already installed @alliage/module-installer you just have to run the following command:
$(npm bin)/alliage-scripts install @alliage/error-handler
Otherwise, update your alliage-modules.json
file to add this at the bottom:
{
// ... other modules
"@alliage/error-handler": {
"module": "@alliage/error-handler",
"deps": [],
"envs": [],
}
}
Usage
Once installed and registered, the module will work right away without having to do anything specific.
The goal of this module is to display as much details as possible about uncaught exceptions or unhandled rejections. Basically, it will display:
- The name of the error (class name)
- The message
- The stacktrace
- Any public property that is not part of the Error prototype.
So, if you write your own alliage module, don't hesitate to create your custom Error classes and to add as much context as possible in it to let the developers using your module debug their application easily !
Example:
class HttpError extends Error {
constructor(status, body) {
super('An HTTP error occured !');
// These two additional properties will
// be displayed if the error is uncaught
this.status = status;
this.body = body;
}
}
// Later...
throw new HttpError(404, 'Not found');