完整流程加节流 + 高频重试
This commit is contained in:
@@ -37,8 +37,9 @@ http.interceptors.response.use(
|
||||
|
||||
if (error?.config?.url && String(error.config.url).startsWith('/api/v1/admin')) {
|
||||
const status = Number(error?.response?.status || 0)
|
||||
const errorCode = String(error?.response?.data?.errorCode || '').trim()
|
||||
|
||||
if (status === 401) {
|
||||
if (status === 401 && shouldClearAdminSession(errorCode)) {
|
||||
clearAdminSession()
|
||||
|
||||
if (window.location.hash.startsWith('#/admin') && !window.location.hash.startsWith('#/admin/login')) {
|
||||
@@ -81,6 +82,15 @@ function resolveFallbackHttpMessage(error: unknown) {
|
||||
return '接口请求失败'
|
||||
}
|
||||
|
||||
function shouldClearAdminSession(errorCode: string) {
|
||||
return [
|
||||
'admin_auth_required',
|
||||
'admin_auth_invalid',
|
||||
'admin_auth_expired',
|
||||
'admin_auth_user_invalid',
|
||||
].includes(errorCode)
|
||||
}
|
||||
|
||||
export function apiGet<T>(url: string, params?: Record<string, unknown>) {
|
||||
return http.get<ApiEnvelope<T>>(url, { params }) as unknown as Promise<ApiEnvelope<T>>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user