A community based topic aggregation platform built on atproto
at main 73 lines 3.0 kB view raw
1package communitysuggestions 2 3import "errors" 4 5var ( 6 // ErrSuggestionNotFound indicates the requested suggestion does not exist 7 ErrSuggestionNotFound = errors.New("suggestion not found") 8 9 // ErrTitleRequired indicates the suggestion title was not provided 10 ErrTitleRequired = errors.New("suggestion title is required") 11 12 // ErrTitleTooLong indicates the suggestion title exceeds the maximum length 13 ErrTitleTooLong = errors.New("suggestion title exceeds maximum length of 200 characters") 14 15 // ErrDescriptionRequired indicates the suggestion description was not provided 16 ErrDescriptionRequired = errors.New("suggestion description is required") 17 18 // ErrDescriptionTooLong indicates the suggestion description exceeds the maximum length 19 ErrDescriptionTooLong = errors.New("suggestion description exceeds maximum length of 5000 characters") 20 21 // ErrInvalidStatus indicates the suggestion status is not a valid value 22 ErrInvalidStatus = errors.New("invalid suggestion status: must be one of open, under_review, approved, declined") 23 24 // ErrInvalidVoteValue indicates the vote value is not valid (must be 1 or -1) 25 ErrInvalidVoteValue = errors.New("invalid vote value: must be 1 or -1") 26 27 // ErrInvalidSuggestionID indicates the suggestion ID is invalid 28 ErrInvalidSuggestionID = errors.New("invalid suggestion ID: must be a positive integer") 29 30 // ErrVoterRequired indicates the voter DID was not provided 31 ErrVoterRequired = errors.New("voter DID is required") 32 33 // ErrSubmitterRequired indicates the submitter DID was not provided 34 ErrSubmitterRequired = errors.New("submitter DID is required") 35 36 // ErrNotAuthorized indicates the user is not authorized to perform the action 37 ErrNotAuthorized = errors.New("not authorized to perform this action") 38 39 // ErrRateLimitExceeded indicates the user has exceeded the suggestion creation rate limit 40 ErrRateLimitExceeded = errors.New("rate limit exceeded: maximum 3 suggestions per day") 41 42 // ErrVoteNotFound indicates the requested vote does not exist 43 ErrVoteNotFound = errors.New("vote not found") 44) 45 46// IsValidationError checks if an error is a validation error 47func IsValidationError(err error) bool { 48 return errors.Is(err, ErrTitleRequired) || 49 errors.Is(err, ErrTitleTooLong) || 50 errors.Is(err, ErrDescriptionRequired) || 51 errors.Is(err, ErrDescriptionTooLong) || 52 errors.Is(err, ErrInvalidStatus) || 53 errors.Is(err, ErrInvalidVoteValue) || 54 errors.Is(err, ErrInvalidSuggestionID) || 55 errors.Is(err, ErrVoterRequired) || 56 errors.Is(err, ErrSubmitterRequired) 57} 58 59// IsNotFound checks if an error is a "not found" error 60func IsNotFound(err error) bool { 61 return errors.Is(err, ErrSuggestionNotFound) || 62 errors.Is(err, ErrVoteNotFound) 63} 64 65// IsRateLimitError checks if an error is a rate limit error 66func IsRateLimitError(err error) bool { 67 return errors.Is(err, ErrRateLimitExceeded) 68} 69 70// IsAuthorizationError checks if an error is an authorization error 71func IsAuthorizationError(err error) bool { 72 return errors.Is(err, ErrNotAuthorized) 73}