express-err
Basic error handler for express. This middleware shows errors according to the "Accept" header. It will shutdown app in case of uncaught error.
Install
yarn add express-err
Usage
const app = // Basic route.app // Redirect other routes to 404.app // Handle errors.app
errorHandler(options)
The error handler middleware is used to display errors and shutdown app in case of uncaught error.
The avalaible options are:
exitOnUncaughtException
Tell to the process to exit on uncaught exceptions. Defaults to true
.
app
exitCode
The code used to exit app in case of uncaught exception. Defaults to 1
.
app
defaultStatusCode
The default HTTP error code. Defaults to 500
.
app
formatters
The error handler come with some preconfigured formatters, one for "json", "text" and "html". It's possible to provide your own formatters:
app
httpError(status, [message])
You can use httpError to return a custom error with a status and a message, if you don't provide a message, it will automatically use the HTTP status.
app
new HttpError(status, [message])
You can create a custom HttpError with a status and a message, if you don't provide a message, it will automatically use the HTTP status.
app
License
MIT