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()
}