-
Notifications
You must be signed in to change notification settings - Fork 6
/
errors.js
43 lines (32 loc) · 1.08 KB
/
errors.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
module.exports = function(app){
app.use(function(req, res){
res.status(404);
//Respond with html page
if (req.accepts('html')) {
res.render('error.handlebars', {ErrorCode:404,ErrorDesc:"The page you requested was not found...oops" });
return;
}
//Default to plain-text. send()
res.type('txt').send('404 Not Found');
});
app.use(function(req, res){
res.status(403);
//Respond with html page
if (req.accepts('html')) {
res.render('error', {ErrorCode:403,ErrorDesc:"Forbidden." });
return;
}
//Default to plain-text. send()
res.type('txt').send('403 Forbidden');
});
app.use(function(req, res){
res.status(500);
//Respond with html page
if (req.accepts('html')) {
res.render('error', {ErrorCode:500,ErrorDesc:"There was an Internal Server Error...sorry :(" });
return;
}
//Default to plain-text. send()
res.type('txt').send('500 Internal Server Error');
});
};