mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-17 16:06:38 +08:00
fix: fix gemini panic
This commit is contained in:
parent
b91a269ddb
commit
bba6174745
28
middleware/recover.go
Normal file
28
middleware/recover.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
|
"one-api/common"
|
||||||
|
"runtime/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RelayPanicRecover() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
common.SysError(fmt.Sprintf("panic detected: %v", err))
|
||||||
|
common.SysError(fmt.Sprintf("stacktrace from panic: %s", string(debug.Stack())))
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"error": gin.H{
|
||||||
|
"message": fmt.Sprintf("Panic detected, error: %v. Please submit a issue here: https://github.com/songquanpeng/one-api", err),
|
||||||
|
"type": "one_api_panic",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,12 @@ type QuotaData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateQuotaData() {
|
func UpdateQuotaData() {
|
||||||
|
// recover
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
common.SysLog(fmt.Sprintf("UpdateQuotaData panic: %s", r))
|
||||||
|
}
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
if common.DataExportEnabled {
|
if common.DataExportEnabled {
|
||||||
common.SysLog("正在更新数据看板数据...")
|
common.SysLog("正在更新数据看板数据...")
|
||||||
|
@ -17,7 +17,7 @@ func SetRelayRouter(router *gin.Engine) {
|
|||||||
modelsRouter.GET("/:model", controller.RetrieveModel)
|
modelsRouter.GET("/:model", controller.RetrieveModel)
|
||||||
}
|
}
|
||||||
relayV1Router := router.Group("/v1")
|
relayV1Router := router.Group("/v1")
|
||||||
relayV1Router.Use(middleware.TokenAuth(), middleware.Distribute())
|
relayV1Router.Use(middleware.RelayPanicRecover(), middleware.TokenAuth(), middleware.Distribute())
|
||||||
{
|
{
|
||||||
relayV1Router.POST("/completions", controller.Relay)
|
relayV1Router.POST("/completions", controller.Relay)
|
||||||
relayV1Router.POST("/chat/completions", controller.Relay)
|
relayV1Router.POST("/chat/completions", controller.Relay)
|
||||||
|
Loading…
Reference in New Issue
Block a user