From 4c53ef7cae721743be3d5aa54d7b05a20fdd2599 Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Wed, 18 Feb 2026 11:21:54 +0100 Subject: [PATCH] fix: add response.ok checks before .json() in CandleChart.tsx Added HTTP error checks before calling .json() in the three fetch functions (fetchCandles, fetchAnnotations, fetchAnnotationTypes) to prevent silent failures on non-2xx responses. Marks task 4.12 as complete in tasks.md. Co-Authored-By: Claude Sonnet 4.6 --- openspec/changes/code-review-fix/tasks.md | 2 +- src/components/CandleChart.tsx | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/openspec/changes/code-review-fix/tasks.md b/openspec/changes/code-review-fix/tasks.md index ec2d8e6..950ed97 100644 --- a/openspec/changes/code-review-fix/tasks.md +++ b/openspec/changes/code-review-fix/tasks.md @@ -37,7 +37,7 @@ - [x] 4.9 `[haiku]` Add `parseInt(value, 10)` with `isNaN()` guard to all routes parsing integer query params - [x] 4.10 `[sonnet]` Add CSV injection protection (prefix `=+@-` cells with `'`) to all export routes - [x] 4.11 `[sonnet]` Add `response.ok` checks before `.json()` in `src/app/page.tsx` (lines 214, 230, 245, 257) -- [ ] 4.12 `[sonnet]` Add `response.ok` checks before `.json()` in `src/components/CandleChart.tsx` (lines 163, 178, 192) +- [x] 4.12 `[sonnet]` Add `response.ok` checks before `.json()` in `src/components/CandleChart.tsx` (lines 163, 178, 192) ## 5. ML Service Hardening (Python) diff --git a/src/components/CandleChart.tsx b/src/components/CandleChart.tsx index cb6a8c3..ba3336b 100644 --- a/src/components/CandleChart.tsx +++ b/src/components/CandleChart.tsx @@ -161,6 +161,7 @@ const CandleChart = forwardRef( try { const url = activeChartId ? `/api/candles?chartId=${activeChartId}` : '/api/candles'; const response = await fetch(url); + if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); const data = await response.json(); setCandles(data); setIsEmpty(data.length === 0); @@ -176,6 +177,7 @@ const CandleChart = forwardRef( try { const url = activeChartId ? `/api/annotations?chartId=${activeChartId}` : '/api/annotations'; const response = await fetch(url); + if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); const data = await response.json(); setAnnotations(data); return data; @@ -189,6 +191,7 @@ const CandleChart = forwardRef( const fetchAnnotationTypes = async () => { try { const response = await fetch('/api/annotation-types'); + if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); const data = await response.json(); setAnnotationTypes(data.filter((t: AnnotationType) => t.is_active)); return data;