pcgamedb/server/middleware/recover.go
nite07 304517e241
Some checks failed
release / goreleaser (push) Failing after 2m23s
docker / prepare-and-build (push) Failing after 2m55s
trans to private
2024-11-20 19:09:04 +08:00

23 lines
405 B
Go

package middleware
import (
"net/http"
"pcgamedb/log"
"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()
}
}