{"record":{"id":"aa43275ad5683185","repo":"sveltejs/kit","slug":"invalid-query-live-response","errorCode":null,"errorMessage":"Invalid query.live response","messagePattern":"Invalid query\\.live response","errorType":"http","errorClass":"HttpError","httpStatus":500,"severity":"error","filePath":"packages/kit/src/runtime/client/remote-functions/query-live/iterator.js","lineNumber":47,"sourceCode":"\t});\n\n\t// detect new deployments from the response header\n\tnotify_version(response.headers.get('x-sveltekit-version'));\n\n\tif (!response.ok) {\n\t\t/** @type {RemoteFunctionResponse | undefined} */\n\t\tconst result = await response.json().catch(() => undefined);\n\n\t\tthrow result?.type === 'error'\n\t\t\t? new HandledHttpError(result.error)\n\t\t\t: new HttpError({ status: response.status, message: response.statusText });\n\t}\n\n\tif (response.headers.get('content-type')?.includes('application/json')) {\n\t\t// we can end up here if we e.g. redirect in `handle`\n\t\tconst result = await response.json();\n\t\tawait handle_side_channel_response(result);\n\t\tthrow new HttpError({ status: 500, message: 'Invalid query.live response' });\n\t}\n\n\tif (!response.body) {\n\t\tthrow new Error('Expected query.live response body to be a ReadableStream');\n\t}\n\n\tconst reader = response.body.getReader();\n\n\ttry {\n\t\ton_connect();\n\n\t\tfor await (const node of read_sse(reader)) {\n\t\t\tif (node.type === 'result') {\n\t\t\t\tyield devalue.parse(node.result, app.decoders);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tawait handle_side_channel_response(node);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/remote-functions/query-live/iterator.js#L29-L65","documentation":"The query.live client expects a streaming (non-JSON) response. If the response content-type is application/json, it parses the body, surfaces any side-channel result, then throws HttpError 500 'Invalid query.live response' because a JSON body cannot be a live stream.","triggerScenarios":"The query.live endpoint's response was replaced by a JSON response — commonly because a redirect or handle() hook rewrote the response, or the request hit a normal JSON route/error page instead of the streaming endpoint.","commonSituations":"Custom server handle hook intercepting and short-circuiting requests; redirect issued inside handle for the streaming request; proxy/gateway returning a JSON error page (auth walls, 502 pages); middleware converting responses to JSON.","solutions":["Inspect the server handle hook and exclude/exempt the query.live (event.request url containing __data or the remote endpoint) requests from rewriting/redirecting","Check for redirects triggered for that request (auth redirects) and allow the streaming endpoint through","Check reverse-proxy config so it doesn't replace streaming responses with JSON error pages","Verify the client and server @sveltejs/kit versions match"],"exampleFix":"// before\nexport const handle = async ({ event, resolve }) => {\n  if (!event.locals.user) redirect(307, '/login'); // also catches stream requests\n  return resolve(event);\n};\n// after\nexport const handle = async ({ event, resolve }) => {\n  if (!event.locals.user && !event.url.pathname.startsWith('/_app/remote')) {\n    redirect(307, '/login');\n  }\n  return resolve(event);\n};","handlingStrategy":"try-catch","validationCode":"const res = await fetch(endpoint, { headers: { accept: 'text/event-stream' } });\nconst ct = res.headers.get('content-type') ?? '';\nif (ct.includes('application/json')) throw new Error('endpoint returned JSON, not a stream');","typeGuard":"const isStreaming = (res) => !(res.headers.get('content-type') ?? '').includes('application/json');","tryCatchPattern":"try {\n  await query.live(...);\n} catch (e) {\n  if (e.status === 500 && e.message === 'Invalid query.live response') {\n    // check handle hook/redirect/proxy and retry\n  } else throw e;\n}","preventionTips":["Exempt streaming endpoints from handle-hook rewrites and redirects","Ensure proxies don't convert streams to JSON error pages","Keep client/server kit versions in sync"],"tags":["query-live","network","content-type","streaming"],"backgroundTag":"invalid-query-live-response","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}