express-json-err
v1.1.1
Published
Express error handlers for JSON APIs
Maintainers
Readme
⋔ 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)vsapp.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_ENVis"development".
Errors
4xx errors are exposed to the client. Properties exposed are:
messagetypenamecodestatus
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