mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-22 06:08:44 -05:00
[server] Do not use separate error recovery
This commit is contained in:
@@ -15,11 +15,15 @@ import (
|
||||
func createEngine() *gin.Engine {
|
||||
engine := gin.New()
|
||||
engine.Use(gin.Logger(), gin.CustomRecovery(func(c *gin.Context, err any) {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
||||
"status": 500,
|
||||
"code": "internal_server_error",
|
||||
"msg": "Internal Server Error",
|
||||
})
|
||||
if e, ok := err.(*errors.Error); ok {
|
||||
c.AbortWithStatusJSON(e.Status, e)
|
||||
} else {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
||||
"status": 500,
|
||||
"code": "internal_server_error",
|
||||
"msg": "Internal Server Error",
|
||||
})
|
||||
}
|
||||
}))
|
||||
if Cfg.LogBody {
|
||||
engine.Use(logBodyMiddleware)
|
||||
@@ -39,19 +43,5 @@ func createEngine() *gin.Engine {
|
||||
}))
|
||||
}
|
||||
|
||||
engine.Use(func(c *gin.Context) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if e, ok := err.(*errors.Error); ok {
|
||||
c.AbortWithStatusJSON(e.Status, e)
|
||||
} else {
|
||||
// This will be caught by the regular gin error recovery handler
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
c.Next()
|
||||
})
|
||||
|
||||
return engine
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user