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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user