jsonapi-errors
Express middleware that sends errors in JSON-API compliant format.
It prevents error.stack leaking in non-development mode.
ES6 compatible node@^4.3.1
engine required.
Usage
const app = const jsonapiErrors = // import errorsconst errors = const BadRequestError = errorsBadRequestErrorconst DbError = errorsDbErrorconst ForbiddenError = errorsForbiddenErrorconst NotFoundError = errorsNotFoundErrorconst UnauthorizedError = errorsUnauthorizedError // or with 'node --harmony_destructuring' flagconst BadRequestError DbError ForbiddenError NotFoundError UnauthorizedError } = // place here json-api routes// they handle errors this way: next(new ForbiddenError('User has insufficient access rights')) // place jsonapi-errors middleware after all api routes// so it can catch, format, and send errors in JSON-API formatapp
The json result of
will be
License
It is licensed under the MIT License.