From 91a44e1ba823973cf50a974049d4391d963f910e Mon Sep 17 00:00:00 2001 From: zhang <823772544@qq.com> Date: Mon, 9 Feb 2026 15:33:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E6=8E=A8=E7=90=86=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E5=A4=A7=E6=A8=A1=E5=9E=8B=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E3=80=82=E8=BF=9E=E6=8E=A5=E6=9C=AA=E5=85=B3?= =?UTF-8?q?=E9=97=AD=EF=BC=8C=E4=B8=94=E6=B2=A1=E6=9C=89=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/impl/AbstractStreamingChatService.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/chat/impl/AbstractStreamingChatService.java b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/chat/impl/AbstractStreamingChatService.java index 98db8c29..c8389004 100644 --- a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/chat/impl/AbstractStreamingChatService.java +++ b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/service/chat/impl/AbstractStreamingChatService.java @@ -225,6 +225,21 @@ public abstract class AbstractStreamingChatService implements IChatService { @Override public void onError(Throwable error) { log.error("{}流式响应错误: {}", getProviderName(), error.getMessage(), error); + + // 发送错误消息到前端 + try { + String errorMessage = String.format("模型调用失败: %s", error.getMessage()); + SseMessageUtils.sendMessage(userId, errorMessage); + } catch (Exception e) { + log.error("发送错误消息失败: {}", e.getMessage(), e); + } + + // 关闭SSE连接,避免前端一直等待 + try { + SseMessageUtils.completeConnection(userId, tokenValue); + } catch (Exception e) { + log.error("关闭SSE连接失败: {}", e.getMessage(), e); + } } }; }