@valbo/error-handler-middleware
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

@valbo/error-handler-middleware

Express error middleware that sends the error as a json response.

npm (scoped) semantic-release Build Status Coverage Status Known Vulnerabilities

Install

npm install @valbo/error-handler-middleware

Usage

Add it to express at the end of the middleware chain to capture the error thrown and send it as a JSON response:

import { errorHandlerMiddleware } from '@valbo/error-handler-middleware';

// at the end of the middleware chain
app.use(errorHandlerMiddleware);

This error response will have the following format:

{
  "error" : {
    "status": 400,
    "name": "BadRequestError",
    "message": ".find should NOT have additional properties"
  }
}

The status will be error.status, error.statusCode or 500 as a default.

The name will be error.name or InternalServerError as a default.

It will also store the error sent in response.locals.responseError if you want to do something else with it, like logging.

Readme

Keywords

Package Sidebar

Install

npm i @valbo/error-handler-middleware

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

18.1 kB

Total Files

24

Last publish

Collaborators

  • valbo