feat: 完善服务端工程化、发布流程和自动化测试
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { formatToken, getToken } from "@/utils/auth";
|
||||
import { formatToken, getToken, removeToken } from "@/utils/auth";
|
||||
|
||||
export class AdminApiError extends Error {
|
||||
status: number;
|
||||
@@ -70,6 +70,12 @@ export async function adminRequest<T = any>(
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 401) {
|
||||
removeToken();
|
||||
if (window.location.pathname !== "/login") {
|
||||
window.location.href = "/login";
|
||||
}
|
||||
}
|
||||
throw new AdminApiError(
|
||||
`HTTP ${response.status}: ${text || response.statusText}`,
|
||||
response.status,
|
||||
@@ -122,6 +128,12 @@ export async function downloadAdminFile(
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
if (response.status === 401) {
|
||||
removeToken();
|
||||
if (window.location.pathname !== "/login") {
|
||||
window.location.href = "/login";
|
||||
}
|
||||
}
|
||||
throw new AdminApiError(
|
||||
`HTTP ${response.status}: ${text || response.statusText}`,
|
||||
response.status,
|
||||
|
||||
Reference in New Issue
Block a user