From 7ad123227aeb5433227130053d715940edcfca54 Mon Sep 17 00:00:00 2001 From: weibaohui Date: Wed, 16 Oct 2024 16:00:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20SSE=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=E5=B0=86=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=E6=9C=BA=E5=88=B6=E4=BB=8E?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E6=9B=B4=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=90=91=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=8F=91=E9=80=81=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=B6=88=E6=81=AF=EF=BC=8C=E5=B9=B6=E5=9C=A8=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=94=99=E8=AF=AF=E6=B6=88=E6=81=AF=E5=90=8E=E4=B8=AD?= =?UTF-8?q?=E6=96=AD=E5=BE=AA=E7=8E=AF=E3=80=82=E8=BF=99=E6=A0=B7=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=AE=A9=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=9B=B4=E5=8F=8A?= =?UTF-8?q?=E6=97=B6=E5=9C=B0=E4=BA=86=E8=A7=A3=E5=88=B0=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E5=8F=91=E7=94=9F=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E4=BA=86=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=E7=9A=84?= =?UTF-8?q?=E6=95=88=E7=8E=87=E5=92=8C=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/controller/sse/sse.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/controller/sse/sse.go b/pkg/controller/sse/sse.go index 4382b20..86bdc38 100644 --- a/pkg/controller/sse/sse.go +++ b/pkg/controller/sse/sse.go @@ -2,6 +2,7 @@ package sse import ( "bufio" + "fmt" "io" "log" "net/http" @@ -30,7 +31,10 @@ func WriteSSE(c *gin.Context, stream io.ReadCloser) { if err == io.EOF { break } - log.Fatalf("Error reading log stream: %v", err) + // 处理读取错误,向客户端发送错误消息 + c.SSEvent("error", fmt.Sprintf("Error reading stream: %v", err)) + c.Writer.Flush() + break } // 发送 SSE 消息 c.SSEvent("message", line)