forked from DebaucheryLibrarian/traxxx
23 lines
524 B
JavaScript
Executable File
23 lines
524 B
JavaScript
Executable File
'use strict';
|
|
|
|
const argv = require('../argv');
|
|
const logger = require('../logger')(__filename);
|
|
|
|
function errorHandler(error, req, res, _next) {
|
|
logger.warn(`Failed to fulfill request to ${req.path}: ${error.message}`);
|
|
|
|
if (argv.debug) {
|
|
logger.error(error);
|
|
}
|
|
|
|
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;
|