mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-12 03:13:41 +08:00
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:
@@ -3,6 +3,8 @@ package middleware
|
||||
import (
|
||||
"strings"
|
||||
|
||||
gmw "github.com/Laisky/gin-middlewares/v6"
|
||||
"github.com/Laisky/zap"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/songquanpeng/one-api/common"
|
||||
@@ -21,6 +23,18 @@ func abortWithMessage(c *gin.Context, statusCode int, message string) {
|
||||
logger.Error(c.Request.Context(), message)
|
||||
}
|
||||
|
||||
func abortWithError(c *gin.Context, statusCode int, err error) {
|
||||
logger := gmw.GetLogger(c)
|
||||
logger.Error("server abort", zap.Error(err))
|
||||
c.JSON(statusCode, gin.H{
|
||||
"error": gin.H{
|
||||
"message": helper.MessageWithRequestId(err.Error(), c.GetString(helper.RequestIdKey)),
|
||||
"type": "one_api_error",
|
||||
},
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
|
||||
func getRequestModel(c *gin.Context) (string, error) {
|
||||
var modelRequest ModelRequest
|
||||
err := common.UnmarshalBodyReusable(c, &modelRequest)
|
||||
|
||||
Reference in New Issue
Block a user