21 lines
325 B
Go
Raw Normal View History

2024-09-25 13:35:38 +02:00
package middleware
import (
"net/http"
2024-09-28 11:13:18 +02:00
"github.com/gin-gonic/gin"
2024-09-25 13:35:38 +02:00
)
// Recovery is a middleware that recovers from the panic
2024-09-28 11:13:18 +02:00
func Recovery() gin.HandlerFunc {
return func(c *gin.Context) {
2024-09-25 13:35:38 +02:00
defer func() {
if err := recover(); err != nil {
2024-09-28 11:13:18 +02:00
c.JSON(http.StatusInternalServerError, err)
2024-09-25 13:35:38 +02:00
}
}()
c.Next()
}
}