29 lines
466 B
Go
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()
|
|
}
|