fix: 接口不再把页面当成运行面板数据

This commit is contained in:
2026-11-03 10:06:23 +08:00
parent a0107c19cc
commit e0d165ed33
2 changed files with 12 additions and 11 deletions
+9 -10
View File
@@ -41,7 +41,7 @@ export async function api<T>(path: string, options: RequestInit = {}): Promise<T
}
const current = token();
if (current) headers.set("Authorization", `Bearer ${current}`);
const response = await fetch(path, { ...options, headers });
const response = await fetch(path, { ...options, headers, cache: "no-store" });
if (response.status === 401) {
setToken("");
sessionStorage.removeItem("decom-role");
@@ -49,18 +49,17 @@ export async function api<T>(path: string, options: RequestInit = {}): Promise<T
sessionStorage.removeItem("decom-id");
sessionStorage.removeItem("decom-kind");
}
if (!response.ok) {
let message = "请求失败";
const text = await response.text();
let payload: { detail?: string } | null = null;
if (text) {
try {
const payload = await response.json();
message = payload.detail || message;
payload = JSON.parse(text) as { detail?: string };
} catch {
message = response.statusText || message;
payload = null;
}
throw new ApiError(response.status, message);
}
if (response.headers.get("content-type")?.includes("application/json")) {
return response.json() as Promise<T>;
if (!response.ok || payload === null) {
throw new ApiError(response.status, payload?.detail || "请求失败");
}
return response as unknown as T;
return payload as T;
}