feat: enhance error handling and reasoning mechanisms across middleware

- Improve error handling across multiple middleware and adapter components, ensuring consistent error response formats in JSON.
- Enhance the functionality of request conversion functions by including context parameters and robust error wrapping.
- Introduce new features related to reasoning content in the messaging model, providing better customization and explanations in the documentation.
This commit is contained in:
Laisky.Cai
2025-02-26 05:38:21 +00:00
parent 07d9a8e144
commit f6cfe7cd4f
13 changed files with 320 additions and 87 deletions

View File

@@ -8,6 +8,7 @@ import (
gutils "github.com/Laisky/go-utils/v5"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/songquanpeng/one-api/common/ctxkey"
"github.com/songquanpeng/one-api/common/logger"
"github.com/songquanpeng/one-api/model"
@@ -31,16 +32,16 @@ func Distribute() func(c *gin.Context) {
if ok {
id, err := strconv.Atoi(channelId.(string))
if err != nil {
abortWithMessage(c, http.StatusBadRequest, "Invalid Channel Id")
abortWithError(c, http.StatusBadRequest, errors.New("Invalid Channel Id"))
return
}
channel, err = model.GetChannelById(id, true)
if err != nil {
abortWithMessage(c, http.StatusBadRequest, "Invalid Channel Id")
abortWithError(c, http.StatusBadRequest, errors.New("Invalid Channel Id"))
return
}
if channel.Status != model.ChannelStatusEnabled {
abortWithMessage(c, http.StatusForbidden, "The channel has been disabled")
abortWithError(c, http.StatusForbidden, errors.New("The channel has been disabled"))
return
}
} else {
@@ -53,7 +54,7 @@ func Distribute() func(c *gin.Context) {
logger.SysError(fmt.Sprintf("Channel does not exist: %d", channel.Id))
message = "Database consistency has been broken, please contact the administrator"
}
abortWithMessage(c, http.StatusServiceUnavailable, message)
abortWithError(c, http.StatusServiceUnavailable, errors.New(message))
return
}
}