{"record":{"id":"33fc55432a0d7034","repo":"sigoden/aichat","slug":"invalid-response-event-stream-content-type-cont","errorCode":null,"errorMessage":"Invalid response event-stream. content-type: {content_type}, data: {text}","messagePattern":"Invalid response event-stream\\. content-type: (.+?), data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/client/stream.rs","lineNumber":128,"sourceCode":"            Err(err) => {\n                match err {\n                    EventSourceError::StreamEnded => {}\n                    EventSourceError::InvalidStatusCode(status, res) => {\n                        let text = res.text().await?;\n                        let data: Value = match text.parse() {\n                            Ok(data) => data,\n                            Err(_) => {\n                                bail!(\n                                    \"Invalid response data: {text} (status: {})\",\n                                    status.as_u16()\n                                );\n                            }\n                        };\n                        catch_error(&data, status.as_u16())?;\n                    }\n                    EventSourceError::InvalidContentType(header_value, res) => {\n                        let text = res.text().await?;\n                        bail!(\n                            \"Invalid response event-stream. content-type: {}, data: {text}\",\n                            header_value.to_str().unwrap_or_default()\n                        );\n                    }\n                    _ => {\n                        bail!(\"{}\", err);\n                    }\n                }\n                es.close();\n            }\n        }\n    }\n    Ok(())\n}\n\npub async fn json_stream<S, F, E>(mut stream: S, mut handle: F) -> Result<()>\nwhere\n    S: Stream<Item = Result<bytes::Bytes, E>> + Unpin,","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/client/stream.rs#L110-L146","documentation":"The streaming endpoint responded with a Content-Type that is not text/event-stream (e.g. application/json from a non-streaming API, or text/html from an error page). This means the request reached an HTTP server but not a valid SSE endpoint — typically a wrong base URL, a model/endpoint that does not support streaming, or a proxy stripping the event-stream content type. The response body is dumped to aid diagnosis.","triggerScenarios":"Thrown at src/client/stream.rs:128 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the base URL and path target a streaming-capable SSE endpoint","Check that the model supports streaming and that the request was formed with stream: true","If behind a proxy, ensure it preserves the text/event-stream Content-Type and does not buffer the response","Compare the dumped body with provider docs to identify whether an error JSON was returned instead of a stream"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}