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