swift-eventsource icon indicating copy to clipboard operation
swift-eventsource copied to clipboard

onError 未触发,业务错误响应只能走 onClosed,建议增加响应体支持

Open songdansyz opened this issue 5 months ago • 1 comments

🧩 问题描述

当服务端返回业务错误(如未登录,code=40100),响应为 HTTP 200,但返回内容是 JSON 错误体(非 SSE 格式)。当前情况下:

  • onMessage 不触发
  • onError 也不触发
  • onClosed 被回调,但拿不到任何 response body 或状态码

这导致我们在客户端无法判断为何连接被关闭,也无法给用户弹出提示(比如"未登录,请重新登录")。


🔁 重现步骤

  1. 使用 EventSource 连接接口
  2. 服务端返回如下内容:
{
  "code": 40100,
  "success": false,
  "message": "请登录后再操作"
}
3.客户端只走了 onClosed(),没有触发 onError

期望
希望在 onError(error) 中能收到 HTTP 错误响应内容(包括 statusCode 和 body)

songdansyz avatar Jul 15 '25 06:07 songdansyz

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?

tanderson-ld avatar Jul 25 '25 18:07 tanderson-ld