mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
fix: enhance error handling for frontend session
This commit is contained in:
1 parent
d0e2a4125d
commit
1af85651b8
3 files changed
+29
-27
No files matched your search
+29
-25
@@ -39,36 +39,40 @@ function setQuest(questId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setSession(session) {
|
async function setSession(session) {
|
||||||
store.session = session
|
try {
|
||||||
store.session.graph = new FileGraph(session.graph)
|
store.session = session
|
||||||
term.reset()
|
store.session.graph = new FileGraph(session.graph)
|
||||||
await socket.connect(session)
|
term.reset()
|
||||||
term.focus()
|
await socket.connect(session)
|
||||||
|
term.focus()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
toast.error(err.message)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createSession() {
|
export async function createSession() {
|
||||||
console.log('Creating a new session...')
|
try {
|
||||||
const res = await api.post('/sessions', { questId: store.questId })
|
console.log('Creating a new session...')
|
||||||
const { data } = res
|
const res = await api.post('/sessions', { questId: store.questId })
|
||||||
await setSession(data)
|
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) {
|
async function getActiveSession(questId) {
|
||||||
return api
|
try {
|
||||||
.post('/sessions/active', { questId })
|
const res = await api.post('/sessions/active', { questId })
|
||||||
.then((res) => {
|
await setSession(res.data)
|
||||||
const session = res.data
|
} catch (err) {
|
||||||
return setSession(session)
|
console.error(err)
|
||||||
})
|
toast.warning('Failed to connect previous session. Creating a new one...')
|
||||||
.catch((err) => {
|
await createSession()
|
||||||
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.')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateGraph(event) {
|
function updateGraph(event) {
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ const Quest = model(
|
|||||||
new Schema({
|
new Schema({
|
||||||
_id: {
|
_id: {
|
||||||
type: String,
|
type: String,
|
||||||
unique: true,
|
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export function pushToSession(sessionId, event, ...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function connectContainer(socket, next) {
|
async function connectContainer(socket, next) {
|
||||||
console.log(next)
|
|
||||||
const user = socket.request.session?.passport?.user
|
const user = socket.request.session?.passport?.user
|
||||||
// console.log(user)
|
// console.log(user)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
|||||||
Reference in new issue
Block a user