mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Handle empty responses for JSON endpoints in apiCall function
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user