{"record":{"id":"302c0e0bb30d05fe","repo":"twentyhq/twenty","slug":"invalid-json-response","errorCode":null,"errorMessage":"Invalid JSON response","messagePattern":"Invalid JSON response","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-client-sdk/src/generate/twenty-client-template.ts","lineNumber":381,"sourceCode":"\n    return this.headers ?? {};\n  }\n\n  private shouldRefreshToken(response: GraphqlResponse): boolean {\n    if (response.status === 401) {\n      return true;\n    }\n\n    return hasAuthenticationErrorInGraphqlPayload(response.payload);\n  }\n\n  private assertResponseIsSuccessful(response: GraphqlResponse) {\n    if (response.status < 200 || response.status >= 300) {\n      throw new Error(`${response.statusText}: ${response.rawBody}`);\n    }\n\n    if (response.payload === null) {\n      throw new Error('Invalid JSON response');\n    }\n\n    return response.payload;\n  }\n\n  private async requestRefreshedAccessToken(): Promise<string | null> {\n    const refreshAccessTokenFunction = (\n      globalThis as {\n        frontComponentHostCommunicationApi?: {\n          requestAccessTokenRefresh?: () => Promise<string>;\n        };\n      }\n    ).frontComponentHostCommunicationApi?.requestAccessTokenRefresh;\n\n    if (typeof refreshAccessTokenFunction !== 'function') {\n      return null;\n    }\n","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-client-sdk/src/generate/twenty-client-template.ts#L363-L399","documentation":"Thrown by TwentyClient.assertResponseIsSuccessful (twenty-client-template.ts:380-382) when the response status was 2xx but payload is null. payload is set to null by executeGraphqlRequest (line 341-348) when rawBody is empty or JSON.parse fails — so the body was empty or not valid JSON.","triggerScenarios":"GraphQL endpoint returns 200 OK with an empty body, or with a non-JSON body (HTML error page, plain text). JSON.parse throws inside the try block, payload stays null, and the success assertion rejects it.","commonSituations":"Reverse proxy or CDN returning an empty 200 (e.g. successful CORS preflight surfacing as the response); gateway returning an HTML error page with a 200 status; backend bug returning empty body; gzip/encoding mismatch where text() yields nothing parseable.","solutions":["Inspect response.rawBody from the surrounding context (or reproduce the request with curl) to see what the server actually returned.","Check intermediary proxies/CDNs for HTML error pages masquerading as 200.","Ensure the apiUrl points to the GraphQL endpoint, not a generic web route.","Verify Accept/Content-Type negotiation with the Twenty server."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const result = await client.someQuery();\n} catch (err) {\n  if (err.message === 'Invalid JSON response') {\n    // Reproduce with curl to inspect the raw 2xx body returned by the gateway.\n  }\n}","preventionTips":["Ensure the GraphQL endpoint returns JSON, not HTML.","Verify intermediary proxies do not return empty 200s.","Confirm apiUrl targets the GraphQL route.","Test the endpoint directly with curl before integrating."],"tags":["network","graphql","response-parsing","client-sdk"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}