Skip to content

Commit

Permalink
refactor(flat-server-api): add pmi room not found error code (#2076)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious authored Nov 6, 2023
1 parent f8fb246 commit 308817d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
11 changes: 2 additions & 9 deletions desktop/renderer-app/src/pages/utils/join-room-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestErrorCode, RoomType, isPmiRoom } from "@netless/flat-server-api";
import { RequestErrorCode, RoomType } from "@netless/flat-server-api";
import { roomStore, globalStore } from "@netless/flat-stores";
import { errorTips, message } from "flat-components";
import { FlatI18n } from "@netless/flat-i18n";
Expand Down Expand Up @@ -37,18 +37,11 @@ export const joinRoomHandler = async (
}
} catch (e) {
// if room not found and is pmi room, show wait for teacher to enter
if (
e.message.indexOf(RequestErrorCode.RoomNotFound) > -1 &&
(await checkPmiRoom(formatRoomUUID))
) {
if (e.message.includes(RequestErrorCode.RoomNotFoundAndIsPmi)) {
void message.info(FlatI18n.t("wait-for-teacher-to-enter"));
return;
}
pushHistory(RouteNameType.HomePage);
errorTips(e);
}
};

async function checkPmiRoom(uuid: string): Promise<boolean> {
return /^[0-9]*$/.test(uuid.replace(/\s+/g, "")) && (await isPmiRoom({ pmi: uuid }))?.result;
}
11 changes: 2 additions & 9 deletions packages/flat-pages/src/utils/join-room-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RouteNameType, usePushHistory } from "../utils/routes";
import { roomStore, globalStore } from "@netless/flat-stores";
import { RequestErrorCode, RoomType, isPmiRoom } from "@netless/flat-server-api";
import { RequestErrorCode, RoomType } from "@netless/flat-server-api";
import { errorTips, message } from "flat-components";
import { FlatI18n } from "@netless/flat-i18n";

Expand Down Expand Up @@ -36,18 +36,11 @@ export const joinRoomHandler = async (
}
} catch (e) {
// if room not found and is pmi room, show wait for teacher to enter
if (
e.message.indexOf(RequestErrorCode.RoomNotFound) > -1 &&
(await checkPmiRoom(formatRoomUUID))
) {
if (e.message.includes(RequestErrorCode.RoomNotFoundAndIsPmi)) {
void message.info(FlatI18n.t("wait-for-teacher-to-enter"));
return;
}
pushHistory(RouteNameType.HomePage);
errorTips(e);
}
};

async function checkPmiRoom(uuid: string): Promise<boolean> {
return /^[0-9]*$/.test(uuid.replace(/\s+/g, "")) && (await isPmiRoom({ pmi: uuid }))?.result;
}
2 changes: 2 additions & 0 deletions packages/flat-server-api/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum RequestErrorCode {
RoomNotIsEnded,
RoomNotIsIdle,
RoomExists, // (pmi) room already exists, cannot create new room
RoomNotFoundAndIsPmi, // room not found and the invite code is pmi

PeriodicNotFound = 300000,
PeriodicIsEnded,
Expand Down Expand Up @@ -103,6 +104,7 @@ export const RequestErrorMessage = {
[RequestErrorCode.RoomNotIsEnded]: "the-room-is-not-over-yet",
[RequestErrorCode.RoomNotIsIdle]: "the-room-has-not-yet-started",
[RequestErrorCode.RoomExists]: "the-pmi-room-already-exists",
[RequestErrorCode.RoomNotFoundAndIsPmi]: "wait-for-teacher-to-enter",

[RequestErrorCode.PeriodicNotFound]: "periodic-rooms-do-not-exist",
[RequestErrorCode.PeriodicIsEnded]: "periodic-rooms-have-ended",
Expand Down

0 comments on commit 308817d

Please sign in to comment.