diff --git a/internal/photos/api/errors.go b/internal/photos/api/errors.go new file mode 100644 index 0000000..4732c8a --- /dev/null +++ b/internal/photos/api/errors.go @@ -0,0 +1,31 @@ +package api + +import ( + "errors" + + "github.com/gin-gonic/gin" +) + +var ( + // Session + ErrSessionNotFound = errors.New("session not found") + ErrSessionInvalid = errors.New("session invalid") + ErrTokenMissing = errors.New("token missing") + + // Request + ErrReqMissingBody = errors.New("missing body") + ErrReqNotFound = errors.New("this route doesn't exists") + + // Account + ErrAccountExists = errors.New("account exists") + ErrAccountAuth = errors.New("login or password incorrect") + + // Panic + ErrUnexpected = errors.New("an unexpected error occur") +) + +func (s *Service) Error(c *gin.Context, code int, err error) { + c.AbortWithStatusJSON(code, gin.H{ + "error": err.Error(), + }) +}