From e950ec9dbe16ac5990393a660f7222d721794813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Mih=C3=A1ly?= Date: Fri, 24 Apr 2020 23:42:59 +0200 Subject: [PATCH] Add an error handler to Express to dump OIDC errors with uuid --- server/server.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/server.js b/server/server.js index c3aec39..5188fd1 100755 --- a/server/server.js +++ b/server/server.js @@ -35,6 +35,7 @@ const RedisStore = require('connect-redis')(expressSession); const sharedSession = require('express-socket.io-session'); const interactiveServer = require('./lib/interactiveServer'); const promExporter = require('./lib/promExporter'); +const { v4: uuidv4 } = require('uuid'); /* eslint-disable no-console */ console.log('- process.env.DEBUG:', process.env.DEBUG); @@ -157,6 +158,24 @@ async function run() // Run WebSocketServer. await runWebSocketServer(); + function errorHandler(err, req, res, next) + { + const trackingId = uuidv4(); + + res.status(500).send( + `

Internal Server Error

+

If you report this error, please also report this + tracking ID which makes it possible to locate your session + in the logs which are available to the system administrator: + ${trackingId}

` + ); + logger.error( + 'Express error handler dump with tracking ID: %s, error dump: %o', + trackingId, err); + } + + app.use(errorHandler); + // Log rooms status every 30 seconds. setInterval(() => {