Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fallback for loadSession in case someone might have disconnected. #191

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion components/profileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,21 @@ async function loadSession(
sessionData?: ContractSession,
): Promise<void> {
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!
Expand Down