{"record":{"id":"999d77416c38dc0b","repo":"OtterMind/Chat2DB","slug":"the-response-body-is-empty","errorCode":null,"errorMessage":"The response body is empty.","messagePattern":"The response body is empty\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"chat2db-community-client/src/components/SSERequest/sseFetch.ts","lineNumber":60,"sourceCode":"\n  /** ---------------------- response middleware ---------------------- */\n  if (typeof middlewares.onResponse === 'function') {\n    const modifiedResponse = await middlewares.onResponse(response);\n\n    if (!(modifiedResponse instanceof Response)) {\n      throw new TypeError('The options.onResponse must return a Response instance!');\n    }\n\n    response = modifiedResponse;\n  }\n\n  /** ---------------------- response check ---------------------- */\n  if (!response.ok) {\n    throw new TypeError(`Fetch failed with status ${response.status}`);\n  }\n\n  if (!response.body) {\n    throw new TypeError('The response body is empty.');\n  }\n\n  /** ---------------------- return ---------------------- */\n  return response;\n};\n\nexport default SSEFetch;\n","sourceCodeStart":42,"sourceCodeEnd":68,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-client/src/components/SSERequest/sseFetch.ts#L42-L68","documentation":"sseFetch throws a TypeError when the response has no body (response.body is null/undefined). This check runs after the status-ok check, so the server returned a successful status but with an empty body — which is invalid for an SSE stream that must contain event data. The body stream is required for the downstream sseStream parser to iterate over chunks.","triggerScenarios":"The AI endpoint returns HTTP 200 with an empty body (Content-Length: 0). A misconfigured proxy strips the body. A streaming endpoint sends headers but closes the connection before any data. A redirect that resolves to an empty response.","commonSituations":"Reverse proxy (nginx/cloudflare) buffering configuration drops the stream body. Backend middleware that consumes or discards the body before the SSE handler writes. Network interruption after headers but before body data.","solutions":["Verify the backend SSE endpoint actually writes data to the response body.","Check proxy configuration (disable buffering: proxy_buffering off; X-Accel-Buffering: no).","Handle this specific error in the catch and show 'AI returned no response' to the user.","Confirm the Content-Type header is text/event-stream and the endpoint is not being intercepted by a caching layer."],"exampleFix":"// before\nconst response = await sseFetch(baseURL, requestInit);\n\n// after\ntry {\n  const response = await sseFetch(baseURL, requestInit);\n  // ... process response.body\n} catch (e) {\n  if (e instanceof TypeError && /body is empty/i.test(e.message)) {\n    onError('AI service returned an empty response. Check backend SSE configuration.');\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isEmptyBodyError(e: unknown): e is TypeError {\n  return e instanceof TypeError && /body is empty/i.test(e.message);\n}","tryCatchPattern":"try {\n  const response = await sseFetch(baseURL, requestInit);\n} catch (e) {\n  if (isEmptyBodyError(e)) {\n    onError('AI service returned no data. Check SSE/streaming backend configuration.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Verify the backend SSE endpoint writes to the response body stream.","Disable proxy buffering for streaming endpoints (nginx: proxy_buffering off).","Test the endpoint with curl to confirm it returns streamed data."],"tags":["sse","ai","network","response-handling","frontend"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}