From b8a68820d96040c1525499c547a657c2d59b5060 Mon Sep 17 00:00:00 2001 From: Lennard Fonteijn Date: Thu, 6 Apr 2023 22:46:28 +0200 Subject: [PATCH] Added fallback for loadSession in case someone might have disconnected. (#191) --- components/profileHandler.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/profileHandler.ts b/components/profileHandler.ts index 6cf4b40e..3ab92c09 100644 --- a/components/profileHandler.ts +++ b/components/profileHandler.ts @@ -829,8 +829,21 @@ async function loadSession( sessionData?: ContractSession, ): Promise { if (!sessionData) { - sessionData = await getContractSession(token + "_" + sessionId) + try { + //First, try the loading the session from the filesystem. + sessionData = await getContractSession(token + "_" + sessionId) + } catch (e) { + //Otherwise, see if we still have this session in memory. + //This may be the currently active session, but we need a fallback of some sorts in case a player disconnected. + if (contractSessions.has(sessionId)) { + sessionData = contractSessions.get(sessionId) + } else { + //Rethrow the error + throw e + } + } } + // Update challenge progression with the user's latest progression data for (const cid in sessionData.challengeContexts) { // Make sure the ChallengeProgression is available, otherwise loading might fail!