From 588b025fb1e2555fcccb9e98182d9c2952fe89c5 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Mon, 22 Sep 2025 21:39:44 +0200 Subject: [PATCH] Handle empty responses for JSON endpoints in apiCall function --- webui/src/lib/api.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webui/src/lib/api.ts b/webui/src/lib/api.ts index a3ca0ee..a170246 100644 --- a/webui/src/lib/api.ts +++ b/webui/src/lib/api.ts @@ -44,6 +44,14 @@ async function apiCall( const text = await response.text(); return text as T; } else { + // Handle empty responses for JSON endpoints + const contentLength = response.headers.get('content-length'); + if (contentLength === '0' || contentLength === null) { + const text = await response.text(); + if (text.trim() === '') { + return {} as T; // Return empty object for empty JSON responses + } + } const data = await response.json() as T; return data; }