A community based topic aggregation platform built on atproto
at main 2.0 kB view raw
1package aggregators 2 3import ( 4 "errors" 5 "fmt" 6) 7 8// Domain errors 9var ( 10 ErrAggregatorNotFound = errors.New("aggregator not found") 11 ErrAuthorizationNotFound = errors.New("authorization not found") 12 ErrNotAuthorized = errors.New("aggregator not authorized for this community") 13 ErrAlreadyAuthorized = errors.New("aggregator already authorized for this community") 14 ErrRateLimitExceeded = errors.New("aggregator rate limit exceeded") 15 ErrInvalidConfig = errors.New("invalid aggregator configuration") 16 ErrConfigSchemaValidation = errors.New("configuration does not match aggregator's schema") 17 ErrNotModerator = errors.New("user is not a moderator of this community") 18 ErrNotImplemented = errors.New("feature not yet implemented") // For Phase 2 write-forward operations 19) 20 21// ValidationError represents a validation error with field details 22type ValidationError struct { 23 Field string 24 Message string 25} 26 27func (e *ValidationError) Error() string { 28 return fmt.Sprintf("validation error: %s - %s", e.Field, e.Message) 29} 30 31// NewValidationError creates a new validation error 32func NewValidationError(field, message string) error { 33 return &ValidationError{ 34 Field: field, 35 Message: message, 36 } 37} 38 39// Error classification helpers for handlers to map to HTTP status codes 40func IsNotFound(err error) bool { 41 return errors.Is(err, ErrAggregatorNotFound) || errors.Is(err, ErrAuthorizationNotFound) 42} 43 44func IsValidationError(err error) bool { 45 var validationErr *ValidationError 46 return errors.As(err, &validationErr) || errors.Is(err, ErrInvalidConfig) || errors.Is(err, ErrConfigSchemaValidation) 47} 48 49func IsUnauthorized(err error) bool { 50 return errors.Is(err, ErrNotAuthorized) || errors.Is(err, ErrNotModerator) 51} 52 53func IsConflict(err error) bool { 54 return errors.Is(err, ErrAlreadyAuthorized) 55} 56 57func IsRateLimited(err error) bool { 58 return errors.Is(err, ErrRateLimitExceeded) 59} 60 61func IsNotImplemented(err error) bool { 62 return errors.Is(err, ErrNotImplemented) 63}