express-global-error-handler
installation
yarn add express-global-error-handler
or
npm i express-global-error-handler
usage
const express = const app = const geh = // bind the error handler to the express instance// will receive all unhandled errors thrown from any route handler // produce some errors:app app
usage with express-style error handler
const express = const app = const geh = // use the default handler to forward all errors (including promise rejections) // produce some errors:app // the express default error handler will receive all async errorsapp app
api
(app: express, handler: function?, modes?: <String>)
app
is the express instance to use (or arouter
)handler
is the error handling function (defaults to(err, req, res, next) => next(err)
)modes
is an optional array of express methods to override (defaults to['all', 'get', 'post', 'put', 'delete', 'patch', 'options', 'head', 'use']
)