-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy patherror.js
More file actions
38 lines (31 loc) · 987 Bytes
/
error.js
File metadata and controls
38 lines (31 loc) · 987 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
31
32
33
34
35
36
37
38
/*jslint node: true*/
"use strict";
var fs = require('fs');
function errorPageHandler(err, req, res, next) {
var ldp = req.app.locals.ldp;
// If the user specifies this function
// then, they can customize the error programmatically
if (ldp.errorHandler) {
return ldp.errorHandler(err, req, res, next);
}
// If noErrorPages is set,
// then use built-in express default error handler
if (ldp.noErrorPages) {
return res
.status(err.status)
.send(err.message);
}
// Check if error page exists
var errorPage = ldp.errorPages + err.status.toString() + '.html';
fs.readFile(errorPage, 'utf8', function(readErr, text) {
if (readErr) {
return res
.status(err.status)
.send(err.message);
}
res.status(err.status);
res.header('Content-Type', 'text/html');
res.send(text);
});
}
exports.handler = errorPageHandler;