From 42f1daef827d387765fe0bedfdade8c279be26b3 Mon Sep 17 00:00:00 2001 From: Roland Sadowski Date: Tue, 6 Aug 2024 15:03:29 +0100 Subject: [PATCH] fix: await on redisClient.connect() .connect() is an async function so any errors just get lost (and we may end up stuck loading a page). This change makes the page fail fast and show error page. --- index.js | 2 +- src/serverSetup/session.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c9ccbd9a..98d4c448 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ dotenv.config() const app = express() setupMiddlewares(app) -setupSession(app) +await setupSession(app) setupNunjucks({ app, dataSubjects }) setupRoutes(app) setupSentry(app) diff --git a/src/serverSetup/session.js b/src/serverSetup/session.js index 183b29f6..527b511c 100644 --- a/src/serverSetup/session.js +++ b/src/serverSetup/session.js @@ -5,7 +5,7 @@ import cookieParser from 'cookie-parser' import config from '../../config/index.js' import logger from '../utils/logger.js' -export function setupSession (app) { +export async function setupSession (app) { app.use(cookieParser()) let sessionStore if ('redis' in config) { @@ -16,7 +16,7 @@ export function setupSession (app) { const errorHandler = (err) => { logger.error(`session/setupSession: redis connection error: ${err.code}`) } - redisClient.connect().catch(errorHandler) + await redisClient.connect().catch(errorHandler) sessionStore = new RedisStore({ client: redisClient