Fix projects.map crash on API error response
Build & Auto-Repair / build (push) Has been cancelled

Added res.ok guards on projects and time-tracking pages so that
setProjects receives [] instead of an error object when the API
returns a non-200 response.
This commit is contained in:
2026-07-01 11:35:34 +02:00
parent 838ec9617a
commit 72f872b2f9
2 changed files with 7 additions and 4 deletions
+2 -1
View File
@@ -62,9 +62,10 @@ export default function ProjectsPage() {
if (search) params.set("search", search)
if (statusFilter !== "all") params.set("status", statusFilter)
const res = await fetch(`/api/projects?${params}`)
setProjects(await res.json())
if (res.ok) setProjects(await res.json()); else setProjects([])
} catch (e) {
console.error("Failed to load projects", e)
setProjects([])
} finally {
setLoading(false)
}
+5 -3
View File
@@ -52,11 +52,13 @@ export default function TimeTrackingPage() {
fetch("/api/time-entries/summary"),
fetch("/api/projects"),
])
setEntries(await eRes.json())
setSummary(await sRes.json())
setProjects(await pRes.json())
if (eRes.ok) setEntries(await eRes.json()); else setEntries([])
if (sRes.ok) setSummary(await sRes.json()); else setSummary(null)
if (pRes.ok) setProjects(await pRes.json()); else setProjects([])
} catch (e) {
console.error("Failed to load time data", e)
setEntries([])
setProjects([])
} finally {
setLoading(false)
}