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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user