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 (search) params.set("search", search)
if (statusFilter !== "all") params.set("status", statusFilter) if (statusFilter !== "all") params.set("status", statusFilter)
const res = await fetch(`/api/projects?${params}`) const res = await fetch(`/api/projects?${params}`)
setProjects(await res.json()) if (res.ok) setProjects(await res.json()); else setProjects([])
} catch (e) { } catch (e) {
console.error("Failed to load projects", e) console.error("Failed to load projects", e)
setProjects([])
} finally { } finally {
setLoading(false) setLoading(false)
} }
+5 -3
View File
@@ -52,11 +52,13 @@ export default function TimeTrackingPage() {
fetch("/api/time-entries/summary"), fetch("/api/time-entries/summary"),
fetch("/api/projects"), fetch("/api/projects"),
]) ])
setEntries(await eRes.json()) if (eRes.ok) setEntries(await eRes.json()); else setEntries([])
setSummary(await sRes.json()) if (sRes.ok) setSummary(await sRes.json()); else setSummary(null)
setProjects(await pRes.json()) if (pRes.ok) setProjects(await pRes.json()); else setProjects([])
} catch (e) { } catch (e) {
console.error("Failed to load time data", e) console.error("Failed to load time data", e)
setEntries([])
setProjects([])
} finally { } finally {
setLoading(false) setLoading(false)
} }