Move error handler to be the last middleware

This commit is contained in:
Simon Detheridge 2020-02-14 10:50:52 +00:00
parent 2f67ade3ec
commit e4926e09a7
2 changed files with 4 additions and 7 deletions

View file

@ -16,7 +16,7 @@ const RequestLogger = require('./app/js/RequestLogger')
const app = express()
RequestLogger.attach(app)
app.use(RequestLogger.middleware)
if (settings.sentry && settings.sentry.dsn) {
logger.initializeErrorReporting(settings.sentry.dsn)
@ -140,6 +140,8 @@ app.get('/status', function(req, res) {
app.get('/health_check', healthCheckController.check)
app.use(RequestLogger.errorHandler)
const port = settings.internal.filestore.port || 3009
const host = '0.0.0.0'

View file

@ -15,13 +15,8 @@ class RequestLogger {
this._logMessage = message
}
static attach(app) {
app.use(RequestLogger.middleware)
app.use(RequestLogger.errorHandler)
}
static errorHandler(err, req, res, next) {
req.requestLogger._logInfo.error = err
req.requestLogger.addFields({ error: err })
res
.send(err.message)
.status(500)