Skip to content

0xA-10/express-json-err

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⋔ from expressjs/api-error-handler

The same great module by @jonathanong except with some modernizations:

  • stateless logic
  • deps upgraded
  • supertest replaced with jest
  • configuration option showStackTrace
  • call with default options without parentheses like app.use(jsonError) vs app.use(jsonError({ showStackTrace: true })

express-json-err

An error handler for JSON APIs, meant to be used with http-errors-style errors.

Usage

import jsonError from 'express-json-err';

const app = express()
	.get(...);

app.use(jsonError);
// or with options configured..
app.use(jsonError({ showStackTrace: true } | {} | undefined));

app.listen(...);

API

Response body schema

type ResponseBody = {
	status: number;
	message: string;
	code?: number;
	name?: string;
	type?: string;
	stack?: string;
};

Options

showStackTrace

  • Determines whether the response should contain the error stack trace.
  • By default, stack trace is only included when the environment variable NODE_ENV is "development".

Errors

4xx errors are exposed to the client. Properties exposed are:

  • message
  • type
  • name
  • code
  • status

5xx errors are not exposed to the client. Instead, they are given a generic message as well as the type.

Publishing

bump the version accordingly..

npm run prepublish
npm publish

About

Express error handlers for JSON APIs, modernized.

Resources

License

Stars

Watchers

Forks

Languages

  • TypeScript 97.4%
  • JavaScript 2.6%