This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_handling.js
44 lines (42 loc) · 1.69 KB
/
error_handling.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
44
module.exports = function(app) {
// --------------------------------------------------------------------------------------
const mail = require( './mail' );
// --------------------------------------------------------------------------------------
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Stránka nenalezena');
err.status = 404;
next(err);
});
// --------------------------------------------------------------------------------------
// error handlers
// --------------------------------------------------------------------------------------
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
if(err.status != 404) // do not log 404
console.error(err); // log error to console
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// --------------------------------------------------------------------------------------
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
if(err.status == undefined) { // server failure
var msg = "V aplikaci došlo k chybě. Hlášení o chybě bylo odesláno vývojářům.";
mail.send_error_report(err); // send error report to developers
res.end(msg);
}
res.status(err.status || 500);
var msg = err.message;
res.end(msg);
});
// --------------------------------------------------------------------------------------
}
// --------------------------------------------------------------------------------------