[server] Do not use separate error recovery

This commit is contained in:
Abhishek Shroff
2025-05-29 12:52:18 +05:30
parent c8cac17a86
commit 385db4c7c5
+9 -19
View File
@@ -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
}