From cf6c312e042c3977873caf9065d8bbd77d141874 Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Tue, 16 Jun 2026 10:43:23 +0300 Subject: [PATCH] fix(frontend): don't treat empty 2xx bodies as request failures The API client only skipped JSON parsing for 204, so a success with an empty body (e.g. 201 from POST /pools/:id/files) hit res.json() on an empty stream, threw, and surfaced as "Failed to add to pool" even though the add had committed. Read the body as text and parse only when present. Co-Authored-By: Claude Opus 4.8 --- frontend/src/lib/api/client.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/api/client.ts b/frontend/src/lib/api/client.ts index 6cd0660..92631e4 100644 --- a/frontend/src/lib/api/client.ts +++ b/frontend/src/lib/api/client.ts @@ -128,8 +128,13 @@ async function request(path: string, init?: RequestInit): Promise { invalidateSectionCache(path, (init?.method ?? 'GET').toUpperCase()); + // A success doesn't guarantee a JSON body: 204 never has one, and some 200/201 + // responses (e.g. POST /pools/:id/files) complete with an empty body. Parsing + // those as JSON throws, so read the text first and only parse when present — + // otherwise an empty 201 would surface as a spurious "failed" error. if (res.status === 204) return undefined as T; - return res.json(); + const text = await res.text(); + return (text ? JSON.parse(text) : undefined) as T; } /** Upload with XHR so we can track progress via onProgress(0–100). */