Express error handlers for JSON APIs
npm install api-error-handler-revived 
Forked from api-error-handler since there were unmerged 2016 pull requests
An error handler for JSON APIs, meant to be used with http-errors-style errors.
npm i api-error-handler-revived``js
var errorHandler = require('api-error-handler-revived');
var api = new express.Router();
api.get('/users/:userid', function (req, res, next) {
});
api.use(errorHandler());
app.use('/api', api);
`
#### Options:
- stack:true
- Description: Wether to show or not the stacktrace
- Default: log
- console.error
- Description: Wether to the error objecttrue
- Default: suppressServer
- true
- Description: Wether to supress serverside (5xx) errors with a generic message
- Default:
property to the http-errors properties parameter:
`js
createError(400, There were errors validating sent data, {extra: {errors: validationErrors}})
`$3
4xx errors are exposed to the client.
Properties exposed are:
-
message
- type
- name
- code
- status
- extra properties5xx errors are, by default, not exposed to the client.
Instead, they are given a generic
message as well as the type`.