diff --git a/.changeset/tough-insects-joke.md b/.changeset/tough-insects-joke.md new file mode 100644 index 000000000..de091512a --- /dev/null +++ b/.changeset/tough-insects-joke.md @@ -0,0 +1,5 @@ +--- +'houdini': patch +--- + +Fix error bug JSON response might get treated as non-JSON if it includes `charset` or `boundary` diff --git a/packages/houdini/src/runtime/client/plugins/fetch.ts b/packages/houdini/src/runtime/client/plugins/fetch.ts index 4809e1e94..42489f1dd 100644 --- a/packages/houdini/src/runtime/client/plugins/fetch.ts +++ b/packages/houdini/src/runtime/client/plugins/fetch.ts @@ -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}`