swift-eventsource
swift-eventsource copied to clipboard
onError 未触发,业务错误响应只能走 onClosed,建议增加响应体支持
🧩 问题描述
当服务端返回业务错误(如未登录,code=40100),响应为 HTTP 200,但返回内容是 JSON 错误体(非 SSE 格式)。当前情况下:
onMessage不触发onError也不触发- 仅
onClosed被回调,但拿不到任何 response body 或状态码
这导致我们在客户端无法判断为何连接被关闭,也无法给用户弹出提示(比如"未登录,请重新登录")。
🔁 重现步骤
- 使用
EventSource连接接口 - 服务端返回如下内容:
{
"code": 40100,
"success": false,
"message": "请登录后再操作"
}
3.客户端只走了 onClosed(),没有触发 onError
期望
希望在 onError(error) 中能收到 HTTP 错误响应内容(包括 statusCode 和 body)
Responding with the help of Google translate.
It sounds like the server is responding and then closing the connection. Could you provide a wireshark capture of the socket communication?