fix(api): handle 204 No Content response in delete method
The backend delete endpoint returns 204 No Content with an empty body, but the frontend was attempting to parse the empty response as JSON. This caused a "JSON.parse: unexpected end of data" error when deleting files. The fix adds special handling to not parse JSON for delete responses on success.
This commit is contained in:
@@ -43,6 +43,11 @@ export const api = {
|
||||
const response = await fetch(`${API_BASE}/${name}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
await handleResponse<Record<string, never>>(response);
|
||||
if (!response.ok) {
|
||||
const error: ApiError = await response.json().catch(() => ({ error: 'Unknown error' }));
|
||||
throw new Error(error.error || `HTTP ${response.status}`);
|
||||
}
|
||||
// Don't attempt to parse JSON for 204 No Content
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user