过期跳转
This commit is contained in:
parent
e3ab3cba1e
commit
a1c7803af8
@ -31,6 +31,10 @@ export async function fetchStatisticsOverview({ appCode, countryId, endMs, start
|
||||
headers: requestHeaders(appCode)
|
||||
});
|
||||
const payload = await readJSON(response);
|
||||
if (isAuthExpired(response, payload)) {
|
||||
redirectToLogin();
|
||||
throw new Error(payload.message || "访问凭证已失效");
|
||||
}
|
||||
if (!response.ok || payload.code !== 0) {
|
||||
throw new Error(payload.message || response.statusText || "请求失败");
|
||||
}
|
||||
@ -62,6 +66,17 @@ async function readJSON(response) {
|
||||
}
|
||||
}
|
||||
|
||||
function isAuthExpired(response, payload) {
|
||||
return response.status === 401 || Number(payload?.code) === 40100;
|
||||
}
|
||||
|
||||
function redirectToLogin() {
|
||||
window.localStorage.removeItem(TOKEN_KEY);
|
||||
if (window.location.pathname !== "/login") {
|
||||
window.location.replace("/login");
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeAppCode(value) {
|
||||
return String(value || "").trim().toLowerCase();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user