From da9e1ab293859d2444060eb4bded0b585ff53312 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Mon, 23 Mar 2026 21:10:17 +0100 Subject: [PATCH] fix(core): handle 204 No Content in apiClient JSON parsing The shared apiClient unconditionally called response.json() on every response, including 204 No Content (returned by DELETE endpoints). This caused "Invalid JSON response from server" errors on all delete operations across all modules and personas. Now returns null for 204 responses without attempting JSON parse. Co-Authored-By: Claude Opus 4.6 (1M context) --- static/shared/js/api-client.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/static/shared/js/api-client.js b/static/shared/js/api-client.js index 05c8bbbb..3111a5f6 100644 --- a/static/shared/js/api-client.js +++ b/static/shared/js/api-client.js @@ -127,18 +127,22 @@ class APIClient { apiLog.info(`Response: ${response.status} ${response.statusText} (${duration}ms)`); - // Parse response + // Parse response (handle 204 No Content gracefully) let data; - try { - data = await response.json(); - apiLog.debug('Response data received:', { - hasData: !!data, - dataType: typeof data, - keys: data ? Object.keys(data) : [] - }); - } catch (parseError) { - apiLog.error('Failed to parse JSON response:', parseError); - throw new Error('Invalid JSON response from server'); + if (response.status === 204) { + data = null; + } else { + try { + data = await response.json(); + apiLog.debug('Response data received:', { + hasData: !!data, + dataType: typeof data, + keys: data ? Object.keys(data) : [] + }); + } catch (parseError) { + apiLog.error('Failed to parse JSON response:', parseError); + throw new Error('Invalid JSON response from server'); + } } // Handle 401 Unauthorized - Just clear tokens, DON'T redirect