2022-05-14 19:13:10 +02:00

29 lines
466 B
Go

package photosapi
import (
"errors"
"fmt"
"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, &ErrorWithDetails{
ErrUnexpected.Error(),
[]string{fmt.Sprint(err)},
})
}
}()
c.Next()
}