forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-error-handling.js
More file actions
33 lines (28 loc) · 917 Bytes
/
custom-error-handling.js
File metadata and controls
33 lines (28 loc) · 917 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
var ldnode = require('../'); // or require('ldnode')
var path = require('path');
ldnode
.createServer({
webid: true,
cert: path.resolve('./test/keys/cert.pem'),
key: path.resolve('./test/keys/key.pem'),
errorHandler: function(err, req, res, next) {
if (err.status !== 200) {
console.log('Oh no! There is an error:' + err.message);
res.status(err.status);
// Now you can send the error how you want
// Maybe you want to render an error page
// res.render('errorPage.ejs', {
// title: err.status + ": This is an error!",
// message: err.message
// })
// Or you want to respond in JSON?
res.json({
title: err.status + ": This is an error!",
message: err.message
});
}
}
})
.listen(3456, function() {
console.log('started ldp with webid on port ' + 3456);
});