2021-02-26 18:39:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
2021-03-17 04:11:17 +00:00
|
|
|
const argv = require('../argv');
|
2021-02-26 18:39:48 +00:00
|
|
|
const logger = require('../logger')(__filename);
|
|
|
|
|
|
|
|
function errorHandler(error, req, res, _next) {
|
|
|
|
logger.warn(`Failed to fulfill request to ${req.path}: ${error.message}`);
|
|
|
|
|
2021-03-17 04:11:17 +00:00
|
|
|
if (argv.debug) {
|
|
|
|
logger.error(error);
|
|
|
|
}
|
|
|
|
|
2021-02-26 18:39:48 +00:00
|
|
|
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;
|