feat(error):持久显示系统更新提示
This commit is contained in:
parent
ccfeabc95b
commit
2113e36d57
|
|
@ -5,8 +5,10 @@ import { toast } from "sonner";
|
||||||
import { loadModels } from "./api";
|
import { loadModels } from "./api";
|
||||||
import type { Model } from "./types";
|
import type { Model } from "./types";
|
||||||
|
|
||||||
|
const MODELS_UPDATING_TOAST_ID = "models-server-updating";
|
||||||
|
|
||||||
export function useModels({ enabled = true }: { enabled?: boolean } = {}) {
|
export function useModels({ enabled = true }: { enabled?: boolean } = {}) {
|
||||||
const { data, isLoading, error } = useQuery<Model[], Error>({
|
const { data, isLoading, error, failureReason } = useQuery<Model[], Error>({
|
||||||
queryKey: ["models"],
|
queryKey: ["models"],
|
||||||
queryFn: () => loadModels(),
|
queryFn: () => loadModels(),
|
||||||
enabled,
|
enabled,
|
||||||
|
|
@ -15,16 +17,30 @@ export function useModels({ enabled = true }: { enabled?: boolean } = {}) {
|
||||||
if (queryError.message.startsWith("HTTP error: 4")) {
|
if (queryError.message.startsWith("HTTP error: 4")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (queryError.message.startsWith("Server error: 5")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return failureCount < 1;
|
return failureCount < 1;
|
||||||
},
|
},
|
||||||
|
retryDelay: 3000,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// React Query v5 removed per-query onError callbacks from useQuery options.
|
const serverError = [failureReason, error].find((candidate) =>
|
||||||
if (error?.message.includes("Server error: 5")) {
|
candidate?.message.includes("Server error: 5"),
|
||||||
toast.error("系统正在更新-5,请稍候……");
|
);
|
||||||
|
|
||||||
|
if (serverError) {
|
||||||
|
toast.loading("系统正在更新,请稍候……", {
|
||||||
|
id: MODELS_UPDATING_TOAST_ID,
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast.dismiss(MODELS_UPDATING_TOAST_ID);
|
||||||
|
}, [error, failureReason]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
if (error?.message.includes("HTTP error: 4")) {
|
if (error?.message.includes("HTTP error: 4")) {
|
||||||
toast.error("模型接口不可用,请检查后端路由或服务状态。");
|
toast.error("模型接口不可用,请检查后端路由或服务状态。");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue