2022-05-07 15:38:44 +02:00

29 lines
476 B
Go

package photosapi
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
)
// Errors
var (
ErrUnexpected = errors.New("an unexpected error occur")
)
// Service
func (s *Service) Recovery(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
s.LogErr.Print("PANIC", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"status": StatusFailed,
"error": ErrUnexpected.Error(),
"details": err,
})
}
}()
c.Next()
}