Skip to content

Commit 406877c

Browse files
author
nicola
committed
adding error pages
1 parent 47679c0 commit 406877c

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎lib/handlers/error-pages.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = handler
2+
3+
var debug = require('../debug').server
4+
var fs = require('fs')
5+
6+
function handler (err, req, res, next) {
7+
debug('Error page because of ' + err.message)
8+
9+
var ldp = req.app.locals.ldp
10+
11+
// If the user specifies this function
12+
// then, they can customize the error programmatically
13+
if (ldp.errorHandler) {
14+
return ldp.errorHandler(err, req, res, next)
15+
}
16+
17+
// If noErrorPages is set,
18+
// then use built-in express default error handler
19+
if (ldp.noErrorPages) {
20+
return res
21+
.status(err.status)
22+
.send(err.message)
23+
}
24+
25+
// Check if error page exists
26+
var errorPage = ldp.errorPages + err.status.toString() + '.html'
27+
fs.readFile(errorPage, 'utf8', function (readErr, text) {
28+
if (readErr) {
29+
return res
30+
.status(err.status)
31+
.send(err.message)
32+
}
33+
34+
res.status(err.status)
35+
res.header('Content-Type', 'text/html')
36+
res.send(text)
37+
})
38+
}

0 commit comments

Comments
 (0)