Skip to content

Commit ba4b53b

Browse files
fix: check Content-Type before parsing JSON in fetchExternal (#40958)
When auth is not configured, /.auth/me returns HTML instead of JSON, causing a SyntaxError in the browser console. Added Content-Type validation to throw a descriptive error that the catch block in appSlice handles gracefully, falling back to anonymous user. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ea6367e commit ba4b53b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/App/src/utils/httpClient.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class HttpClient {
6868
if (!response.ok) {
6969
throw new Error(`${config.method || 'GET'} ${url} failed: ${response.statusText}`);
7070
}
71+
const contentType = response.headers.get('content-type') || '';
72+
if (!contentType.includes('application/json')) {
73+
throw new Error(`${config.method || 'GET'} ${url} returned non-JSON response (${contentType})`);
74+
}
7175
return response.json();
7276
}
7377
}

0 commit comments

Comments
 (0)