v1.2.35: 增强News页面API错误处理

This commit is contained in:
甲辰生产 2026-03-31 20:02:24 +08:00
parent 49d2b3fccc
commit 190d11347f
1 changed files with 8 additions and 0 deletions

View File

@ -73,11 +73,19 @@ export default function News() {
// token便matched_count // token便matched_count
const headers = token ? { Authorization: `Bearer ${token}` } : {} const headers = token ? { Authorization: `Bearer ${token}` } : {}
const res = await fetch(`${API_BASE}/api/information/list?info_type=${type}`, { headers }) const res = await fetch(`${API_BASE}/api/information/list?info_type=${type}`, { headers })
//
if (!res.ok) {
console.error('获取资讯列表失败:', res.status)
setInfoList([])
setLoading(false)
return
}
const data = await res.json() const data = await res.json()
console.log('资讯列表:', data) console.log('资讯列表:', data)
setInfoList(data || []) setInfoList(data || [])
} catch (e) { } catch (e) {
console.error(e) console.error(e)
setInfoList([])
} }
setLoading(false) setLoading(false)
} }