Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/App/src/utils/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class HttpClient {
if (!response.ok) {
throw new Error(`${config.method || 'GET'} ${url} failed: ${response.statusText}`);
}
const contentType = response.headers.get('content-type') || '';

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message can be unhelpful when the server omits the Content-Type header (you'll end up with returned non-JSON response ()). Consider distinguishing between a missing header and a non-JSON header value so the thrown error is actionable during debugging.

Suggested change
const contentType = response.headers.get('content-type') || '';
const contentType = response.headers.get('content-type');
if (!contentType) {
throw new Error(`${config.method || 'GET'} ${url} returned response missing Content-Type header`);
}

Copilot uses AI. Check for mistakes.
if (!contentType.includes('application/json')) {

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON detection is overly strict: valid JSON responses may use vendor/problem types like application/problem+json or application/vnd.api+json, and header values are case-insensitive. Consider normalizing to lowercase and accepting application/json or any +json media type (per RFC 6839) to avoid false negatives.

Suggested change
if (!contentType.includes('application/json')) {
const normalizedContentType = contentType.toLowerCase();
const mediaType = normalizedContentType.split(';', 1)[0].trim();
const isJsonResponse = mediaType === 'application/json' || mediaType.endsWith('+json');
if (!isJsonResponse) {

Copilot uses AI. Check for mistakes.
throw new Error(`${config.method || 'GET'} ${url} returned non-JSON response`);
}
return response.json();
Comment on lines +71 to 75

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says the HttpClient now ensures all HTTP responses are JSON before parsing, but this validation is only added to fetchExternal(); the core request() path still calls response.json() unconditionally. Either broaden the check to request() as well or adjust the PR description to match the actual behavior.

Copilot uses AI. Check for mistakes.
}
}
Expand Down
Loading