Miss any of our Open RFC calls?Watch the recordings here! »

express-json-error-handler

4.0.0 • Public • Published

express-json-error-handler Build Status Coverage Status

Error handler for express JSON APIs

Install

$ npm install express-json-error-handler

Usage

Example

import express from 'express';
import jsonErrorHandler from 'express-json-error-handler';
 
const app = express();
 
app.use(jsonErrorHandler());
 

Options

The jsonErrorHandler function takes an option options object that may contain any of the following keys:

log

The log option, if supplied, is called as log({err, req, res}) when server errors occur.

Example

import express from 'express';
import jsonErrorHandler from 'express-json-error-handler';
 
const app = express();
 
app.use(jsonErrorHandler({
  log({err, req, res}) {
    console.log(err); // The original error object
    console.log(req); // The request object
    console.log(res); // The response object
  }
}));
 

License

MIT

Install

npm i express-json-error-handler

DownloadsWeekly Downloads

223

Version

4.0.0

License

MIT

Unpacked Size

20.6 kB

Total Files

18

Last publish

Collaborators

  • avatar