-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.js
More file actions
30 lines (24 loc) · 696 Bytes
/
Copy patherrors.js
File metadata and controls
30 lines (24 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
//
//
var errorMiddleware = function(app, status) {
// Catch 404 errors and throw into error handler
app.use(function(req, res/* , next */) {
var err = new Error('Page Not Found');
err.status = status.NOT_FOUND;
throw err;
});
// error handler
app.use(function(err, req, res, next ) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
if (res.headersSent) {
return next(err);
}
// render the error page
res.status(err.status || status.INTERNAL_SERVER_ERROR);
res.render('error');
});
};
module.exports = errorMiddleware;