fix: enhance error handling for frontend session

This commit is contained in:
wancat authored and Lin, Hung-Shin committed 2023-11-14 10:45:24 +08:00
1 parent d0e2a4125d
commit 1af85651b8
3 files changed
+29 -27

No files matched your search

+29 -25
View File
@@ -39,36 +39,40 @@ function setQuest(questId) {
}
async function setSession(session) {
store.session = session
store.session.graph = new FileGraph(session.graph)
term.reset()
await socket.connect(session)
term.focus()
try {
store.session = session
store.session.graph = new FileGraph(session.graph)
term.reset()
await socket.connect(session)
term.focus()
} catch (err) {
console.error(err)
toast.error(err.message)
throw err
}
}
export async function createSession() {
console.log('Creating a new session...')
const res = await api.post('/sessions', { questId: store.questId })
const { data } = res
await setSession(data)
try {
console.log('Creating a new session...')
const res = await api.post('/sessions', { questId: store.questId })
const { data } = res
await setSession(data)
} catch (err) {
console.error(err)
toast.error('Failed to create a new session. Please try again later.')
}
}
function getActiveSession(questId) {
return api
.post('/sessions/active', { questId })
.then((res) => {
const session = res.data
return setSession(session)
})
.catch((err) => {
console.log(err)
toast.warning('Failed to connect previous session. Creating a new one...')
return createSession()
})
.catch((err) => {
console.log(err)
toast.error('Failed to create a new session. Please try again later.')
})
async function getActiveSession(questId) {
try {
const res = await api.post('/sessions/active', { questId })
await setSession(res.data)
} catch (err) {
console.error(err)
toast.warning('Failed to connect previous session. Creating a new one...')
await createSession()
}
}
function updateGraph(event) {
-1
View File
@@ -73,7 +73,6 @@ const Quest = model(
new Schema({
_id: {
type: String,
unique: true,
required: true,
},
title: {
-1
View File
@@ -28,7 +28,6 @@ export function pushToSession(sessionId, event, ...args) {
}
async function connectContainer(socket, next) {
console.log(next)
const user = socket.request.session?.passport?.user
// console.log(user)
if (!user) {