fixed: go-api => 增加全局错误处理 handler,修复业务处理异常导致服务退出的 Bug

This commit is contained in:
RockYang
2023-06-25 11:34:55 +08:00
parent eadb9a733f
commit d20cc367b8
5 changed files with 18 additions and 12 deletions

View File

@@ -25,7 +25,7 @@ import (
"gorm.io/gorm"
)
const ErrorMsg = "抱歉AI 助手开小差了,请马上联系管理员去盘它。"
const ErrorMsg = "抱歉AI 助手开小差了,请稍后再试。"
type ChatHandler struct {
BaseHandler
@@ -218,7 +218,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
}
err = json.Unmarshal([]byte(line[6:]), &responseBody)
if err != nil { // 数据解析出错
if err != nil || len(responseBody.Choices) == 0 { // 数据解析出错
logger.Error(err, line)
replyMessage(ws, ErrorMsg)
replyMessage(ws, "![](/images/wx.png)")