From c4d1a122b29116d6302a0fc62bb56f8f9a7807d8 Mon Sep 17 00:00:00 2001 From: kurihada Date: Thu, 26 Feb 2026 20:10:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20fetch=20=E5=90=8E=E6=A3=80=E6=9F=A5=20re?= =?UTF-8?q?s.ok=20=E5=B9=B6=E6=A0=A1=E9=AA=8C=E6=95=B0=E7=BB=84=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E9=98=B2=E6=AD=A2=E9=94=99=E8=AF=AF=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - panic/page.tsx: suggestions fetch 检查 res.ok + Array.isArray - profile/page.tsx: history/favorites fetch 检查 res.ok + Array.isArray --- src/app/panic/page.tsx | 5 +++-- src/app/profile/page.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/panic/page.tsx b/src/app/panic/page.tsx index 67b056f..cacca66 100644 --- a/src/app/panic/page.tsx +++ b/src/app/panic/page.tsx @@ -70,9 +70,10 @@ export default function PanicPage() { setFetchingSuggestions(true); try { const res = await fetch(`/api/location/suggest?keywords=${encodeURIComponent(query)}`); + if (!res.ok) { setSuggestions([]); setShowSuggestions(false); return; } const data: LocationSuggestion[] = await res.json(); - setSuggestions(data); - setShowSuggestions(data.length > 0); + setSuggestions(Array.isArray(data) ? data : []); + setShowSuggestions(Array.isArray(data) && data.length > 0); } catch { setSuggestions([]); } finally { diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index ac5d760..b980046 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -93,15 +93,15 @@ export default function ProfilePage() { setHistoryLoading(true); fetch(`/api/user/history?userId=${userId}`) - .then((r) => r.json()) - .then(setHistory) + .then((r) => { if (!r.ok) throw new Error(); return r.json(); }) + .then((data) => setHistory(Array.isArray(data) ? data : [])) .catch(() => {}) .finally(() => setHistoryLoading(false)); setFavLoading(true); fetch(`/api/user/favorite?userId=${userId}`) - .then((r) => r.json()) - .then(setFavorites) + .then((r) => { if (!r.ok) throw new Error(); return r.json(); }) + .then((data) => setFavorites(Array.isArray(data) ? data : [])) .catch(() => {}) .finally(() => setFavLoading(false)); }, [userId]);