update
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
@import './base.css';
|
@import './base.css';
|
||||||
@import 'tailwindcss';
|
@import 'tailwindcss/theme' layer(theme);
|
||||||
|
@import 'tailwindcss/utilities' layer(utilities);
|
||||||
|
|
||||||
/* 应用全局样式 */
|
/* 应用全局样式 */
|
||||||
#app {
|
#app {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ async function request<T = unknown>(url: string, options: RequestOptions = {}):
|
|||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 401 未授权:跳过登录/注册接口(由页面自行处理错误提示),其余接口重定向到登录页
|
// 401 未授权:登录/注册接口解析后端错误信息,其余接口重定向到登录页
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
const isAuthEndpoint = /\/api\/v1\/(login|register)$/.test(url)
|
const isAuthEndpoint = /\/api\/v1\/(login|register)$/.test(url)
|
||||||
if (!isAuthEndpoint) {
|
if (!isAuthEndpoint) {
|
||||||
@@ -64,8 +64,14 @@ async function request<T = unknown>(url: string, options: RequestOptions = {}):
|
|||||||
window.location.pathname + window.location.search,
|
window.location.pathname + window.location.search,
|
||||||
)
|
)
|
||||||
window.location.href = `/login?redirect=${redirect}`
|
window.location.href = `/login?redirect=${redirect}`
|
||||||
|
throw new ApiError('登录已过期,请重新登录', 401)
|
||||||
}
|
}
|
||||||
throw new ApiError('登录已过期,请重新登录', 401)
|
let msg = '用户名或密码错误'
|
||||||
|
try {
|
||||||
|
const body = await response.json()
|
||||||
|
if (body.message) msg = body.message
|
||||||
|
} catch { /* ignore parse error */ }
|
||||||
|
throw new ApiError(msg, 401)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防护非 JSON 响应(如网关 HTML 错误页)
|
// 防护非 JSON 响应(如网关 HTML 错误页)
|
||||||
|
|||||||
Reference in New Issue
Block a user