fix(frontend): Handle non-JSON API responses safely in ActivityFeed
Some checks are pending
Deploy Elmeg / deploy (push) Waiting to run
Some checks are pending
Deploy Elmeg / deploy (push) Waiting to run
This commit is contained in:
parent
6ae609985e
commit
ec3e327d94
1 changed files with 19 additions and 5 deletions
|
|
@ -23,11 +23,25 @@ export function ActivityFeed() {
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${getApiUrl()}/feed/`)
|
const fetchFeed = async () => {
|
||||||
.then(res => res.json())
|
try {
|
||||||
.then(setFeed)
|
const res = await fetch(`${getApiUrl()}/feed/`)
|
||||||
.catch(console.error)
|
if (!res.ok) {
|
||||||
.finally(() => setLoading(false))
|
const text = await res.text()
|
||||||
|
console.error('Feed API error:', res.status, text)
|
||||||
|
setFeed([]) // Fallback to empty
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const data = await res.json()
|
||||||
|
setFeed(data)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch feed:', error)
|
||||||
|
setFeed([])
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchFeed()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (loading) return <div>Loading activity...</div>
|
if (loading) return <div>Loading activity...</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue