拆分聊天 Handler 文件职责
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"hfb_sys/backend/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func writeChatError(c *gin.Context, err error) {
|
||||
switch {
|
||||
case errors.Is(err, ErrDependencyUnavailable):
|
||||
response.ServiceUnavailable(c, "聊天服务暂时不可用")
|
||||
case errors.Is(err, ErrConversationNotFound):
|
||||
response.Error(c, http.StatusNotFound, "chat_not_found", "会话不存在")
|
||||
case errors.Is(err, ErrPermissionDenied):
|
||||
response.Error(c, http.StatusForbidden, "permission_denied", "无权访问该会话")
|
||||
case errors.Is(err, ErrInvalidMessage):
|
||||
response.BadRequest(c, "消息内容不符合规则")
|
||||
default:
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "聊天服务暂时不可用")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user