fix: fetch 后检查 res.ok 并校验数组类型,防止错误响应导致崩溃

- panic/page.tsx: suggestions fetch 检查 res.ok + Array.isArray
- profile/page.tsx: history/favorites fetch 检查 res.ok + Array.isArray
This commit is contained in:
2026-02-26 20:10:59 +08:00
parent 5783d522b7
commit c4d1a122b2
2 changed files with 7 additions and 6 deletions
+4 -4
View File
@@ -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]);