Debug: paranna virhekäsittelyä todo_status + apiCall JSON parse

apiCall palauttaa nyt selkeän virheen jos palvelimen vastaus
ei ole validia JSON:ia (+ logittaa console.error). todo_status
palauttaa JSON-virheen myös edge-caseissa.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 13:52:50 +02:00
parent b0c9817aaa
commit e53a6babdb
2 changed files with 10 additions and 3 deletions

View File

@@ -32,7 +32,12 @@ async function apiCall(action, method = 'GET', body = null) {
opts.body = JSON.stringify(body);
}
const res = await fetch(`${API}?action=${action}`, opts);
const data = await res.json();
const text = await res.text();
let data;
try { data = JSON.parse(text); } catch (e) {
console.error('API JSON parse error:', action, text.slice(0, 500));
throw new Error('Palvelin palautti virheellisen vastauksen');
}
if (!res.ok) throw new Error(data.error || 'Virhe');
return data;
}