Skip to content

anatelli10/express-json-error

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⋔ from expressjs/api-error-handler

express-json-error

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

Example

import jsonError from 'express-json-error';

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

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

app.listen(...);

API

after your routes:

app.use(jsonError);
app.use(jsonError(options | {} | undefined));

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.

About

Express error handlers for JSON APIs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 97.2%
  • JavaScript 2.8%