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:
2026-02-06 09:03:05 -05:00
parent 6e9d26fbeb
commit 554f952b6f

View File

@@ -43,6 +43,11 @@ export const api = {
const response = await fetch(`${API_BASE}/${name}`, { const response = await fetch(`${API_BASE}/${name}`, {
method: 'DELETE', 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;
}, },
}; };