⋔ 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 })
An error handler for JSON APIs, meant to be used with http-errors-style errors.
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(...);
type ResponseBody = {
status: number;
message: string;
code?: number;
name?: string;
type?: string;
stack?: string;
};
- 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"
.
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
.
bump the version accordingly..
npm run prepublish
npm publish