fix: add response.ok checks before .json() in page.tsx fetch calls

Guard all four fetch() calls in src/app/page.tsx against non-2xx HTTP
responses by throwing before attempting to parse the body as JSON.
Affected functions: fetchCharts, fetchAnnotations, fetchSpanAnnotations,
fetchSpanLabelTypes.

Marks task 4.11 as completed in code-review-fix/tasks.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marko Djordjevic 2026-02-18 11:21:21 +01:00
parent b2129ad626
commit 4436cd655f
2 changed files with 5 additions and 1 deletions

View file

@ -211,6 +211,7 @@ export default function Home() {
const fetchCharts = useCallback(async () => {
try {
const response = await fetch('/api/charts');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
setCharts(data);
return data as Chart[];
@ -228,6 +229,7 @@ export default function Home() {
}
try {
const response = await fetch(`/api/annotations?chartId=${chartId}`);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
setAnnotations(data);
} catch (error) {
@ -243,6 +245,7 @@ export default function Home() {
}
try {
const response = await fetch(`/api/span-annotations?chartId=${chartId}`);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
setSpanAnnotations(data);
} catch (error) {
@ -254,6 +257,7 @@ export default function Home() {
const fetchSpanLabelTypes = useCallback(async () => {
try {
const response = await fetch('/api/span-label-types');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
setSpanLabelTypes(data);
} catch (error) {