mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-17 07:56:38 +08:00
feat: print user id when error
This commit is contained in:
parent
88cc88c5d0
commit
b7bc205b73
@ -179,8 +179,8 @@ func Max(a int, b int) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MessageWithRequestId(message string, id string, userId int) string {
|
func MessageWithRequestId(message string, id string) string {
|
||||||
return fmt.Sprintf("%s (request id: %s, user id: %d)", message, id, userId)
|
return fmt.Sprintf("%s (request id: %s)", message, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RandomSleep() {
|
func RandomSleep() {
|
||||||
|
@ -82,8 +82,7 @@ func Relay(c *gin.Context) {
|
|||||||
if openaiErr.StatusCode == http.StatusTooManyRequests {
|
if openaiErr.StatusCode == http.StatusTooManyRequests {
|
||||||
openaiErr.Error.Message = "当前分组上游负载已饱和,请稍后再试"
|
openaiErr.Error.Message = "当前分组上游负载已饱和,请稍后再试"
|
||||||
}
|
}
|
||||||
userId := c.GetInt("id")
|
openaiErr.Error.Message = common.MessageWithRequestId(openaiErr.Error.Message, requestId)
|
||||||
openaiErr.Error.Message = common.MessageWithRequestId(openaiErr.Error.Message, requestId, userId)
|
|
||||||
c.JSON(openaiErr.StatusCode, gin.H{
|
c.JSON(openaiErr.StatusCode, gin.H{
|
||||||
"error": openaiErr.Error,
|
"error": openaiErr.Error,
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
)
|
)
|
||||||
@ -9,12 +10,12 @@ func abortWithOpenAiMessage(c *gin.Context, statusCode int, message string) {
|
|||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
c.JSON(statusCode, gin.H{
|
c.JSON(statusCode, gin.H{
|
||||||
"error": gin.H{
|
"error": gin.H{
|
||||||
"message": common.MessageWithRequestId(message, c.GetString(common.RequestIdKey), userId),
|
"message": common.MessageWithRequestId(message, c.GetString(common.RequestIdKey)),
|
||||||
"type": "new_api_error",
|
"type": "new_api_error",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
common.LogError(c.Request.Context(), message)
|
common.LogError(c.Request.Context(), fmt.Sprintf("user %d | %s", userId, message))
|
||||||
}
|
}
|
||||||
|
|
||||||
func abortWithMidjourneyMessage(c *gin.Context, statusCode int, code int, description string) {
|
func abortWithMidjourneyMessage(c *gin.Context, statusCode int, code int, description string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user