diff --git a/src/Helpers/Exceptions.ts b/src/Helpers/Exceptions.ts index ff3631f..145be60 100644 --- a/src/Helpers/Exceptions.ts +++ b/src/Helpers/Exceptions.ts @@ -19,3 +19,14 @@ export class NotTrueError extends Error { super("Server Returned False"); } } + +/** + * @author Aloento + * @since 1.3.0 + * @version 0.1.0 + */ +export class EmptyResponseError extends Error { + public constructor() { + super("Server Returned Empty Response"); + } +} diff --git a/src/ShopNet/SignalR.ts b/src/ShopNet/SignalR.ts index aaac911..7a87ed9 100644 --- a/src/ShopNet/SignalR.ts +++ b/src/ShopNet/SignalR.ts @@ -1,7 +1,7 @@ import { HubConnectionState } from "@microsoft/signalr"; import dayjs, { Dayjs } from "dayjs"; import { Subject } from "rxjs"; -import { NotLoginError, NotTrueError } from "~/Helpers/Exceptions"; +import { EmptyResponseError, NotLoginError, NotTrueError } from "~/Helpers/Exceptions"; import type { Logger } from "~/Helpers/Logger"; import type { AdminNet } from "./Admin/AdminNet"; import { MSAL, Shared, type IConcurrency } from "./Database"; @@ -135,7 +135,7 @@ export abstract class SignalR { if (!res) { Shared.Sto.delete(index); - throw new TypeError("Empty Response"); + throw new EmptyResponseError(); } await Shared.Set(index, { diff --git a/src/ShopNet/User/Get.tsx b/src/ShopNet/User/Get.tsx index 5b7631c..ae75cc2 100644 --- a/src/ShopNet/User/Get.tsx +++ b/src/ShopNet/User/Get.tsx @@ -1,9 +1,7 @@ import { useConst } from "@fluentui/react-hooks"; -import { useBoolean, useMount } from "ahooks"; import { useLiveQuery } from "dexie-react-hooks"; -import { OnNewUserSubject } from "~/Components/NewUser"; import { IPersona } from "~/Components/ShopCart/Persona"; -import { NotLoginError } from "~/Helpers/Exceptions"; +import { EmptyResponseError, NotLoginError } from "~/Helpers/Exceptions"; import type { Logger } from "~/Helpers/Logger"; import { useErrorToast } from "~/Helpers/useToast"; import { IConcurrency } from "../Database"; @@ -27,26 +25,29 @@ export abstract class UserGet extends ShopNet { /** * @author Aloento * @since 1.0.0 - * @version 0.4.1 + * @version 0.4.2 */ public static useMe(pLog: Logger): IUserGetMe | void { const log = useConst(() => pLog.With("|", "Hub", "User", "Get", "Me")); const { dispatch } = useErrorToast(log); - const [onNew, { set }] = useBoolean(); - useMount(() => OnNewUserSubject.subscribe(set)); - - const res = useLiveQuery(() => this.GetVersionCache(0, "UserGetMe") - .catch(e => { - if (onNew || e instanceof NotLoginError) + const res = useLiveQuery(async (): Promise => { + try { + this.EnsureLogin(); + return await this.GetVersionCache(0, "UserGetMe"); + } catch (e) { + if (e instanceof EmptyResponseError) + return; + else if (e instanceof NotLoginError) log.info(e); else dispatch({ Message: "Failed to Get Your Info", - Error: e, + Error: e as Error, Request: "" }); - })); + } + }); return res; }