From 4d1242c9bcd831fa3333c3e9c73a08759741734c Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 20 May 2020 20:33:27 -0700 Subject: [PATCH] Avoid an undefined reference when handed an unknwown game ID We're on our way to a clean 404 error, but we don't want to hit a JavaScript error along the way. --- lmno.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lmno.js b/lmno.js index fbef78f..65c317d 100644 --- a/lmno.js +++ b/lmno.js @@ -133,11 +133,15 @@ app.use('/empires/:game_id([a-zA-Z0-9]{4})', (request, response, next) => { return; } - request.game = lmno.ids[game_id].game; - if (request.game === undefined) { + /* See if there is any game with this ID. */ + const game = lmno.ids[game_id]; + if (game === undefined) { response.sendStatus(404); return; } + + /* Stash the game onto the request to be used by the game-specific code. */ + request.game = game.game; next(); }); -- 2.43.0