Skip to content

Commit

Permalink
改进 SSE读取错误处理将读取错误处理机制从日志记录更改为向客户端发送错误消息,并在发送错误消息后中断循环。这样可以让客户端更及时地了解到…
Browse files Browse the repository at this point in the history
…读取错误的发生,提高了错误处理的效率和用户体验。
  • Loading branch information
weibaohui committed Oct 16, 2024
1 parent 292518a commit 7ad1232
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/controller/sse/sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sse

import (
"bufio"
"fmt"
"io"
"log"
"net/http"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7ad1232

Please sign in to comment.