Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where JSON error response might get treated as non-JSON error response #1407

Merged
merged 9 commits into from
Jan 8, 2025
5 changes: 5 additions & 0 deletions .changeset/tough-insects-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

Fix error bug JSON response might get treated as non-JSON if it includes `charset` or `boundary`
4 changes: 2 additions & 2 deletions packages/houdini/src/runtime/client/plugins/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ const defaultFetch = (
// Avoid parsing the response if it's not JSON, as that will throw a SyntaxError
if (
!result.ok &&
result.headers.get('content-type') !== 'application/json' &&
result.headers.get('content-type') !== 'application/graphql+json'
!result.headers.get('content-type')?.startsWith('application/json') &&
!result.headers.get('content-type')?.startsWith('application/graphql+json')
) {
throw new Error(
`Failed to fetch: server returned invalid response with error ${result.status}: ${result.statusText}`
Expand Down
Loading