Skip to content

Commit

Permalink
fix: await on redisClient.connect()
Browse files Browse the repository at this point in the history
.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.
  • Loading branch information
rosado committed Aug 6, 2024
1 parent 87baf69 commit 42f1dae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dotenv.config()
const app = express()

setupMiddlewares(app)
setupSession(app)
await setupSession(app)
setupNunjucks({ app, dataSubjects })
setupRoutes(app)
setupSentry(app)
Expand Down
4 changes: 2 additions & 2 deletions src/serverSetup/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 42f1dae

Please sign in to comment.