小飞侠接口调通测试
This commit is contained in:
@@ -33,7 +33,16 @@ export async function request<T>(path: string, options: RequestInit = {}): Promi
|
||||
if (token) headers.Authorization = `Bearer ${token}`;
|
||||
|
||||
const res = await fetch(`${apiBase}${path}`, { ...options, headers });
|
||||
const json = await res.json();
|
||||
const text = await res.text();
|
||||
if (!text.trim()) {
|
||||
throw new Error(`接口空响应(HTTP ${res.status} ${res.statusText || ''})`);
|
||||
}
|
||||
let json: { code: number; message?: string; data?: T };
|
||||
try {
|
||||
json = JSON.parse(text) as { code: number; message?: string; data?: T };
|
||||
} catch {
|
||||
throw new Error(`接口返回非 JSON(HTTP ${res.status}): ${text.slice(0, 200)}`);
|
||||
}
|
||||
if (json.code === 401) {
|
||||
clearAuth();
|
||||
window.location.href = '/login';
|
||||
@@ -70,6 +79,8 @@ export type AdminUserRow = {
|
||||
phone: string | null;
|
||||
phoneVerifiedAt: string | null;
|
||||
mergedIntoUserId: string | null;
|
||||
wxOpenId: string | null;
|
||||
wechatVerified: boolean;
|
||||
nickname: string | null;
|
||||
status: number;
|
||||
createdAt: string;
|
||||
|
||||
Reference in New Issue
Block a user