Skip to content

Commit 8d7d655

Browse files
authored
fix: web page login state (#969)
1 parent 5292538 commit 8d7d655

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/api/axiosRequest.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,19 @@ export const handleApiError = (error: any) => {
6161
message = error.message;
6262
}
6363

64+
const url =
65+
error?.config?.url ||
66+
error?.response?.config?.url ||
67+
error?.request?.config?.url;
68+
69+
const suppressProfileError =
70+
typeof url === "string" && url.includes("/account/profile");
71+
6472
console.error(error);
65-
addError(message, "error");
73+
if (!suppressProfileError) {
74+
addError(message, "error");
75+
}
76+
6677
return error;
6778
};
6879

src/pages/web/index.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useState } from "react";
22
import { useTranslation } from "react-i18next";
3+
import { isPlainObject } from "lodash-es";
34

45
import SearchChat from "@/components/SearchChat";
56
import { useAppStore } from "@/stores/appStore";
@@ -10,12 +11,11 @@ import useEscape from "@/hooks/useEscape";
1011
import { useViewportHeight } from "@/hooks/useViewportHeight";
1112
import type { StartPage } from "@/types/chat";
1213
import ErrorNotification from "@/components/Common/ErrorNotification";
14+
import { Get } from "@/api/axiosRequest";
15+
import { useWebConfigStore } from "@/stores/webConfigStore";
1316

1417
import "@/i18n";
1518
import "@/web.css";
16-
import { Get } from "@/api/axiosRequest";
17-
import { useWebConfigStore } from "@/stores/webConfigStore";
18-
import { isPlainObject } from "lodash-es";
1919

2020
interface WebAppProps {
2121
headers?: Record<string, unknown>;
@@ -83,11 +83,14 @@ function WebApp({
8383
} = useWebConfigStore();
8484

8585
const getUserProfile = async () => {
86-
const [_, result] = await Get("/account/profile");
86+
const [err, result] = await Get("/account/profile");
8787

88-
if (isPlainObject(result)) {
89-
setLoginInfo(result as any);
88+
if (err || !isPlainObject(result)) {
89+
setLoginInfo(void 0);
90+
return;
9091
}
92+
93+
setLoginInfo(result as any);
9194
};
9295

9396
useEffect(() => {

0 commit comments

Comments
 (0)