fix: 移除静默 fallback 数据,API 失败时明确提示用户

This commit is contained in:
2026-02-24 21:16:55 +08:00
parent 07ffe42176
commit 43d3ff0fa3
2 changed files with 56 additions and 47 deletions
+8 -7
View File
@@ -153,20 +153,21 @@ export default function LandingPage() {
body: JSON.stringify({ ...coords, radius, priceRange, cuisine, userId: getUserId() }),
});
const data = await res.json();
if (!res.ok) {
throw new Error("创建房间失败");
throw new Error(data.error || "创建房间失败");
}
const { roomId } = await res.json();
if (!roomId) {
if (!data.roomId) {
throw new Error("创建房间失败");
}
setLoadingText("正在进入房间...");
await joinRoom(roomId);
router.push(`/room/${roomId}`);
} catch {
setError("创建失败,请重试");
await joinRoom(data.roomId);
router.push(`/room/${data.roomId}`);
} catch (e) {
setError(e instanceof Error ? e.message : "创建失败,请重试");
setLoading(false);
setLoadingText("");
}