fix: 房间加载失败时显示具体错误原因,便于线上排查
This commit is contained in:
@@ -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<string | false>(false);
|
||||
|
||||
const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null);
|
||||
const [deletingId, setDeletingId] = useState<string | null>(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() {
|
||||
>
|
||||
<Package size={36} className="text-purple-400/30" strokeWidth={1.5} />
|
||||
<p className="text-sm text-muted">加载房间失败</p>
|
||||
{typeof loadError === "string" && (
|
||||
<p className="max-w-xs text-center text-[11px] text-muted/60 break-all">{loadError}</p>
|
||||
)}
|
||||
<button
|
||||
onClick={() => fetchRooms()}
|
||||
className="mt-1 text-xs font-medium text-purple-400 active:text-purple-300"
|
||||
|
||||
Reference in New Issue
Block a user