From d7b30f00aaf974068a4a3b61a353bf2f9fa405e4 Mon Sep 17 00:00:00 2001 From: Charles Kaup Date: Wed, 8 Jan 2025 17:22:49 -0600 Subject: [PATCH] Fix bug where JSON error response might get treated as non-JSON error response (#1407) --- .changeset/tough-insects-joke.md | 5 +++++ packages/houdini/src/runtime/client/plugins/fetch.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/tough-insects-joke.md 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}`