小飞侠接口调通测试

This commit is contained in:
2026-07-06 17:07:35 +08:00
parent 3625f037d0
commit 4e18763968
8 changed files with 271 additions and 31 deletions
+12 -1
View File
@@ -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(`接口返回非 JSONHTTP ${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;