Added error handler to web server.

This commit is contained in:
DebaucheryLibrarian
2021-02-26 19:39:48 +01:00
parent f018735052
commit 0eba0461c9
5 changed files with 55 additions and 1 deletions

17
src/web/error.js Normal file
View 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;