diff --git a/frontend/src/admin/api.ts b/frontend/src/admin/api.ts index 1bfd8e6..9ab4274 100644 --- a/frontend/src/admin/api.ts +++ b/frontend/src/admin/api.ts @@ -49,14 +49,17 @@ async function request( }) if (!res.ok) { - let detail: unknown + // 先读 text 再尝试 JSON 解析:Response body 流只能读一次, + // 若先调 res.json() 失败(如返回 HTML 错误页),再调 res.text() 会抛 "body stream already read"。 + const rawText = await res.text() + let detail: unknown = rawText try { - detail = await res.json() + detail = JSON.parse(rawText) } catch { - detail = await res.text() + // 非 JSON(如 HTML 错误页),保留原始文本 } let message = - detail && typeof detail === 'object' && 'detail' in detail + detail && typeof detail === 'object' && detail !== null && 'detail' in detail ? String((detail as { detail: unknown }).detail) : `HTTP ${res.status}: ${res.statusText}` // 401 仅在没有显式跳过时广播未登录事件(改密接口的 401 表示当前密码错误,非会话过期) diff --git a/src/api/routes/matches.py b/src/api/routes/matches.py index f2ead70..89e647d 100644 --- a/src/api/routes/matches.py +++ b/src/api/routes/matches.py @@ -4,7 +4,7 @@ from __future__ import annotations from datetime import datetime, timedelta from fastapi import APIRouter, Depends, HTTPException, Query -from sqlalchemy import or_, select +from sqlalchemy import func, or_, select from sqlalchemy.orm import selectinload from src.api.deps import require_admin