2024-09-24 06:17:11 -04:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-11-15 02:02:45 -05:00
|
|
|
|
2024-11-20 06:09:04 -05:00
|
|
|
"pcgamedb/log"
|
2024-09-24 06:17:11 -04:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Recovery() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
defer func() {
|
|
|
|
if rec := recover(); rec != nil {
|
|
|
|
log.Logger.Error("Recovery", zap.Any("error", rec), zap.Stack("stacktrace"))
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"status": "error"})
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|