From 333581c5ef897f07c4d5d79e5273273837d11eab Mon Sep 17 00:00:00 2001 From: Till JS Date: Sun, 10 May 2026 17:07:24 +0200 Subject: [PATCH] =?UTF-8?q?fix(web):=20body=20stream=20already=20read=20?= =?UTF-8?q?=E2=80=94=20Text=20zuerst=20lesen,=20dann=20JSON=20parsen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit res.json() konsumiert den Body-Stream auch bei SyntaxError, danach schlägt res.text() mit 'body stream already read' fehl. Fix: text() einmalig lesen, dann JSON.parse() versuchen. Co-Authored-By: Claude Sonnet 4.6 --- apps/web/src/lib/api/client.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/apps/web/src/lib/api/client.ts b/apps/web/src/lib/api/client.ts index a1e0d14..f9504e1 100644 --- a/apps/web/src/lib/api/client.ts +++ b/apps/web/src/lib/api/client.ts @@ -71,12 +71,9 @@ export async function apiForm(path: string, form: FormData): Promise { const res = await fetch(`${API_BASE}${path}`, { method: 'POST', headers, body: form }); if (!res.ok) { - let body: unknown = null; - try { - body = await res.json(); - } catch { - body = await res.text(); - } + const text = await res.text(); + let body: unknown = text; + try { body = JSON.parse(text); } catch { /* keep text */ } throw new ApiError(res.status, body); } return (await res.json()) as T; @@ -105,12 +102,9 @@ export async function api(path: string, opts: RequestOptions = {}): Promise