mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-17 16:06:38 +08:00
fix: recover panic
This commit is contained in:
parent
a5e0f86c65
commit
64862cd634
10
main.go
10
main.go
@ -104,7 +104,15 @@ func main() {
|
|||||||
|
|
||||||
// Initialize HTTP server
|
// Initialize HTTP server
|
||||||
server := gin.New()
|
server := gin.New()
|
||||||
server.Use(gin.Recovery())
|
server.Use(gin.CustomRecovery(func(c *gin.Context, err any) {
|
||||||
|
common.SysError(fmt.Sprintf("panic detected: %v", err))
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"error": gin.H{
|
||||||
|
"message": fmt.Sprintf("Panic detected, error: %v. Please submit a issue here: https://github.com/Calcium-Ion/new-api", err),
|
||||||
|
"type": "new_api_panic",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}))
|
||||||
// This will cause SSE not to work!!!
|
// This will cause SSE not to work!!!
|
||||||
//server.Use(gzip.Gzip(gzip.DefaultCompression))
|
//server.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||||
server.Use(middleware.RequestId())
|
server.Use(middleware.RequestId())
|
||||||
|
@ -16,8 +16,8 @@ func RelayPanicRecover() gin.HandlerFunc {
|
|||||||
common.SysError(fmt.Sprintf("stacktrace from panic: %s", string(debug.Stack())))
|
common.SysError(fmt.Sprintf("stacktrace from panic: %s", string(debug.Stack())))
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": gin.H{
|
"error": gin.H{
|
||||||
"message": fmt.Sprintf("Panic detected, error: %v. Please submit a issue here: https://github.com/songquanpeng/one-api", err),
|
"message": fmt.Sprintf("Panic detected, error: %v. Please submit a issue here: https://github.com/Calcium-Ion/new-api", err),
|
||||||
"type": "one_api_panic",
|
"type": "new_api_panic",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
|
Loading…
Reference in New Issue
Block a user