@forhot2000/express-json-error-handler
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

express-json-error-handler

Error handler for express JSON APIs

Install

$ npm install @forhot2000/express-json-error-handler

Usage

Example

import express from 'express';
import jsonErrorHandler from '@forhot2000/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 '@forhot2000/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
    },
  }),
);

Package Sidebar

Install

npm i @forhot2000/express-json-error-handler

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

4.66 kB

Total Files

6

Last publish

Collaborators

  • forhot2000