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 <noreply@anthropic.com>
This commit is contained in:
Marko Djordjevic 2026-02-18 11:21:54 +01:00
parent 4436cd655f
commit 4c53ef7cae
2 changed files with 4 additions and 1 deletions

View file

@ -161,6 +161,7 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
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<CandleChartHandle, CandleChartProps>(
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<CandleChartHandle, CandleChartProps>(
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;