diff --git a/src/app/blindbox/page.tsx b/src/app/blindbox/page.tsx index 7478b8c..3412f68 100644 --- a/src/app/blindbox/page.tsx +++ b/src/app/blindbox/page.tsx @@ -179,7 +179,7 @@ export default function BlindboxLobbyPage() { const [creating, setCreating] = useState(false); const [joining, setJoining] = useState(false); const [error, setError] = useState(""); - const [loadError, setLoadError] = useState(false); + const [loadError, setLoadError] = useState(false); const [confirmDeleteId, setConfirmDeleteId] = useState(null); const [deletingId, setDeletingId] = useState(null); @@ -193,12 +193,15 @@ export default function BlindboxLobbyPage() { } try { const res = await fetch(`/api/blindbox/rooms?userId=${p.id}`, { cache: "no-store" }); - if (!res.ok) throw new Error(); + if (!res.ok) { + const body = await res.json().catch(() => null); + throw new Error(body?.error ?? `HTTP ${res.status}`); + } const data = await res.json(); setRooms(Array.isArray(data.rooms) ? data.rooms : []); setLoadError(false); - } catch { - if (!silent) setLoadError(true); + } catch (e) { + if (!silent) setLoadError(e instanceof Error ? e.message : "未知错误"); } finally { if (!silent) setLoading(false); } @@ -434,6 +437,9 @@ export default function BlindboxLobbyPage() { >

加载房间失败

+ {typeof loadError === "string" && ( +

{loadError}

+ )}