diff --git a/desktop/renderer-app/src/pages/utils/join-room-handler.ts b/desktop/renderer-app/src/pages/utils/join-room-handler.ts index f5df2cbecbc..72296d99753 100644 --- a/desktop/renderer-app/src/pages/utils/join-room-handler.ts +++ b/desktop/renderer-app/src/pages/utils/join-room-handler.ts @@ -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"; @@ -37,10 +37,7 @@ 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; } @@ -48,7 +45,3 @@ export const joinRoomHandler = async ( errorTips(e); } }; - -async function checkPmiRoom(uuid: string): Promise { - return /^[0-9]*$/.test(uuid.replace(/\s+/g, "")) && (await isPmiRoom({ pmi: uuid }))?.result; -} diff --git a/packages/flat-pages/src/utils/join-room-handler.ts b/packages/flat-pages/src/utils/join-room-handler.ts index 371751a28ed..0304e177532 100644 --- a/packages/flat-pages/src/utils/join-room-handler.ts +++ b/packages/flat-pages/src/utils/join-room-handler.ts @@ -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"; @@ -36,10 +36,7 @@ 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; } @@ -47,7 +44,3 @@ export const joinRoomHandler = async ( errorTips(e); } }; - -async function checkPmiRoom(uuid: string): Promise { - return /^[0-9]*$/.test(uuid.replace(/\s+/g, "")) && (await isPmiRoom({ pmi: uuid }))?.result; -} diff --git a/packages/flat-server-api/src/error.ts b/packages/flat-server-api/src/error.ts index ffda75dec0c..a8a28a519df 100644 --- a/packages/flat-server-api/src/error.ts +++ b/packages/flat-server-api/src/error.ts @@ -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, @@ -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",