Fail-express is an express error-handler middleware for JSON APIs. This library uses http-status.
const express = require('express');
const failExpress = require('fail-express');
const app = new express();
const router = express().Router();
router.get('/status', (req, res, next) => {
res.send('Online!');
});
app.use('/api/v1', router);
router.use(failExpress());
const failExpress = require('fail-express');
Use the new fail-express middleware function using the given options
.
fail-express accepts this properties in the options object.
Function that receives the error object with its default properties. Default fail-express error reporter:
const defaultErrorReporter = error => {
console.error(error.stack);
};
Appends the error stack trace to the error object.
Appends additional properties to the error object.
Default properties:
message
type
name
code
status