We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ac63569 commit 40701a9Copy full SHA for 40701a9
1 file changed
frontend/src/services/api.ts
@@ -15,6 +15,11 @@ async function request<T>(url: string, options: RequestInit = {}): Promise<T> {
15
const res = await fetch(`${BASE}${url}`, { ...options, headers });
16
17
if (!res.ok) {
18
+ if (res.status === 401 && !url.includes('/auth/login') && !url.includes('/auth/register')) {
19
+ localStorage.removeItem('oj_token');
20
+ window.location.href = '/login';
21
+ throw new Error('登录已过期,请重新登录');
22
+ }
23
const err = await res.json().catch(() => ({ error: '网络错误' }));
24
throw new Error(err.error || `请求失败 (${res.status})`);
25
}
0 commit comments