v1.2.35: 增强News页面API错误处理
This commit is contained in:
parent
49d2b3fccc
commit
190d11347f
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue