diff --git a/app/src/store/session.js b/app/src/store/session.js index e363f5e..4c85f76 100644 --- a/app/src/store/session.js +++ b/app/src/store/session.js @@ -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) { diff --git a/packages/models/quest.js b/packages/models/quest.js index 3634183..04c9d10 100644 --- a/packages/models/quest.js +++ b/packages/models/quest.js @@ -73,7 +73,6 @@ const Quest = model( new Schema({ _id: { type: String, - unique: true, required: true, }, title: { diff --git a/server/src/api/socket.js b/server/src/api/socket.js index 3ead062..7a0c542 100644 --- a/server/src/api/socket.js +++ b/server/src/api/socket.js @@ -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) {