You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

25 lines
492 B

package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
func RecoveryMiddleware(logger *zap.Logger) gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
logger.Error("Panic recovered",
zap.Any("error", err),
zap.String("path", c.Request.URL.Path),
)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"error": "Internal Server Error",
})
}
}()
c.Next()
}
}