1.0.5 • Published 3 years ago

@valbo/error-handler-middleware v1.0.5

Weekly downloads
38
License
MIT
Repository
github
Last release
3 years ago

@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.

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago