A community based topic aggregation platform built on atproto
1package comments
2
3import "errors"
4
5var (
6 // ErrCommentNotFound indicates the requested comment doesn't exist
7 ErrCommentNotFound = errors.New("comment not found")
8
9 // ErrInvalidReply indicates the reply reference is malformed or invalid
10 ErrInvalidReply = errors.New("invalid reply reference")
11
12 // ErrParentNotFound indicates the parent post/comment doesn't exist
13 ErrParentNotFound = errors.New("parent post or comment not found")
14
15 // ErrRootNotFound indicates the root post doesn't exist
16 ErrRootNotFound = errors.New("root post not found")
17
18 // ErrContentTooLong indicates comment content exceeds 10000 graphemes
19 ErrContentTooLong = errors.New("comment content exceeds 10000 graphemes")
20
21 // ErrContentEmpty indicates comment content is empty
22 ErrContentEmpty = errors.New("comment content is required")
23
24 // ErrNotAuthorized indicates the user is not authorized to perform this action
25 ErrNotAuthorized = errors.New("not authorized")
26
27 // ErrBanned indicates the user is banned from the community
28 ErrBanned = errors.New("user is banned from this community")
29
30 // ErrCommentAlreadyExists indicates a comment with this URI already exists
31 ErrCommentAlreadyExists = errors.New("comment already exists")
32
33 // ErrConcurrentModification indicates the comment was modified since it was loaded
34 ErrConcurrentModification = errors.New("comment was modified by another operation")
35)
36
37// IsNotFound checks if an error is a "not found" error
38func IsNotFound(err error) bool {
39 return errors.Is(err, ErrCommentNotFound) ||
40 errors.Is(err, ErrParentNotFound) ||
41 errors.Is(err, ErrRootNotFound)
42}
43
44// IsConflict checks if an error is a conflict/already exists error
45func IsConflict(err error) bool {
46 return errors.Is(err, ErrCommentAlreadyExists) ||
47 errors.Is(err, ErrConcurrentModification)
48}
49
50// IsValidationError checks if an error is a validation error
51func IsValidationError(err error) bool {
52 return errors.Is(err, ErrInvalidReply) ||
53 errors.Is(err, ErrContentTooLong) ||
54 errors.Is(err, ErrContentEmpty)
55}