forked from DebaucheryLibrarian/traxxx
Added error handler to web server.
This commit is contained in:
17
src/web/error.js
Normal file
17
src/web/error.js
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const logger = require('../logger')(__filename);
|
||||
|
||||
function errorHandler(error, req, res, _next) {
|
||||
logger.warn(`Failed to fulfill request to ${req.path}: ${error.message}`);
|
||||
|
||||
if (error.httpCode) {
|
||||
res.status(error.httpCode).send(error.message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(500).send('Oops... our server messed up. We will be investigating this incident, our apologies for the inconvenience.');
|
||||
}
|
||||
|
||||
module.exports = errorHandler;
|
||||
Reference in New Issue
Block a user