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)
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${getApiUrl()}/feed/`)
|
||||
.then(res => res.json())
|
||||
.then(setFeed)
|
||||
.catch(console.error)
|
||||
.finally(() => setLoading(false))
|
||||
const fetchFeed = async () => {
|
||||
try {
|
||||
const res = await fetch(`${getApiUrl()}/feed/`)
|
||||
if (!res.ok) {
|
||||
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>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue