]> git.cworth.org Git - empires-server/commitdiff
Avoid an undefined reference when handed an unknwown game ID
authorCarl Worth <cworth@cworth.org>
Thu, 21 May 2020 03:33:27 +0000 (20:33 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 21 May 2020 03:33:27 +0000 (20:33 -0700)
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

diff --git a/lmno.js b/lmno.js
index fbef78f208a7decfd46300b094c29ce554b22515..65c317d05f37bb1b964781dd84b1b6d0f3b0f1ab 100644 (file)
--- 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();
 });