Handle empty responses for JSON endpoints in apiCall function

This commit is contained in:
2025-09-22 21:39:44 +02:00
parent 6dcf0f806e
commit 588b025fb1

View File

@@ -44,6 +44,14 @@ async function apiCall<T>(
const text = await response.text(); const text = await response.text();
return text as T; return text as T;
} else { } 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; const data = await response.json() as T;
return data; return data;
} }