veza/veza-backend-api/internal/services/errors.go

99 lines
3.5 KiB
Go

package services
import "errors"
// Common service errors
var (
// ErrUserAlreadyExists is returned when trying to create a user that already exists
ErrUserAlreadyExists = errors.New("user already exists")
// ErrInvalidCredentials is returned when login credentials are invalid
ErrInvalidCredentials = errors.New("invalid credentials")
// ErrUserNotFound is returned when a user is not found
ErrUserNotFound = errors.New("user not found")
// ErrInvalidToken is returned when a token is invalid or expired
ErrInvalidToken = errors.New("invalid or expired token")
// ErrWeakPassword is returned when password doesn't meet requirements
ErrWeakPassword = errors.New("password does not meet security requirements")
// ErrInvalidEmail is returned when email format is invalid
ErrInvalidEmail = errors.New("invalid email format")
// ErrPlaylistNotFound is returned when a playlist is not found
ErrPlaylistNotFound = errors.New("playlist not found")
// ErrTrackNotFound is returned when a track is not found
ErrTrackNotFound = errors.New("track not found")
// ErrForbidden is returned when access is denied
ErrForbidden = errors.New("forbidden")
// ErrAccessDenied is alias for ErrForbidden
ErrAccessDenied = ErrForbidden
// ErrTrackAlreadyInPlaylist is returned when adding a duplicate track
ErrTrackAlreadyInPlaylist = errors.New("track already in playlist")
// ErrTitleEmpty is returned when title is empty
ErrTitleEmpty = errors.New("title cannot be empty")
// ErrTitleTooLong is returned when title exceeds limit
ErrTitleTooLong = errors.New("title must be less than 200 characters")
// ErrInvalidTrackID is returned when track ID is invalid/nil
ErrInvalidTrackID = errors.New("invalid track ID")
// ErrInvalidUserID is returned when user ID is invalid/nil
ErrInvalidUserID = errors.New("invalid user ID")
// ErrInvalidBitrate is returned when bitrate is invalid
ErrInvalidBitrate = errors.New("invalid bitrate")
// ErrInvalidBufferLevel is returned when buffer level is invalid
ErrInvalidBufferLevel = errors.New("invalid buffer level")
// ErrCommentNotFound is returned when a comment is not found
ErrCommentNotFound = errors.New("comment not found")
// ErrParentCommentNotFound is returned when a parent comment is not found
ErrParentCommentNotFound = errors.New("parent comment not found")
// ErrParentTrackMismatch is returned when parent comment is on different track
ErrParentTrackMismatch = errors.New("parent comment belongs to a different track")
// ErrRoomNotFound is returned when a room/conversation is not found
ErrRoomNotFound = errors.New("conversation not found")
)
// IsUserAlreadyExistsError checks if the error is a user already exists error
func IsUserAlreadyExistsError(err error) bool {
return errors.Is(err, ErrUserAlreadyExists)
}
// IsInvalidCredentialsError checks if the error is an invalid credentials error
func IsInvalidCredentialsError(err error) bool {
return errors.Is(err, ErrInvalidCredentials)
}
// IsUserNotFoundError checks if the error is a user not found error
func IsUserNotFoundError(err error) bool {
return errors.Is(err, ErrUserNotFound)
}
// IsInvalidTokenError checks if the error is an invalid token error
func IsInvalidTokenError(err error) bool {
return errors.Is(err, ErrInvalidToken)
}
// IsWeakPassword checks if the error is a weak password error
func IsWeakPassword(err error) bool {
return errors.Is(err, ErrWeakPassword)
}
// IsInvalidEmail checks if the error is an invalid email error
func IsInvalidEmail(err error) bool {
return errors.Is(err, ErrInvalidEmail)
}