litebb/middlewares/handlers.middleware.js

1const notFound = (req, res, next) => { 2 const err = { 3 status: 404, 4 message: 'Not found' 5 } 6 next(err); 7}; 8 9const errorHandler = (err, req, res, next) => { 10 11 // set locals, only providing error in development 12 res.locals.status = err.status || 500; 13 res.locals.message = err.message; 14 res.locals.error = req.app.get('env') === 'development' ? (err.stack || '') : ''; 15 16 // render the error page 17 res.status(err.status || 500); 18 res.render('error'); 19} 20 21module.exports = { 22 errorHandler, 23 notFound 24}