A community based topic aggregation platform built on atproto
at main 1.6 kB view raw
1package users 2 3import ( 4 "errors" 5 "fmt" 6) 7 8// Sentinel errors for common user operations 9var ( 10 // ErrUserNotFound is returned when a user lookup finds no matching record 11 ErrUserNotFound = errors.New("user not found") 12 13 // ErrHandleAlreadyTaken is returned when attempting to use a handle that belongs to another user 14 ErrHandleAlreadyTaken = errors.New("handle already taken") 15) 16 17// Domain errors for user service operations 18// These map to lexicon error types defined in social.coves.actor.signup 19 20type InvalidHandleError struct { 21 Handle string 22 Reason string 23} 24 25func (e *InvalidHandleError) Error() string { 26 return fmt.Sprintf("invalid handle %q: %s", e.Handle, e.Reason) 27} 28 29type HandleNotAvailableError struct { 30 Handle string 31} 32 33func (e *HandleNotAvailableError) Error() string { 34 return fmt.Sprintf("handle %q is not available", e.Handle) 35} 36 37type InvalidInviteCodeError struct { 38 Code string 39} 40 41func (e *InvalidInviteCodeError) Error() string { 42 return "invalid or expired invite code" 43} 44 45type InvalidEmailError struct { 46 Email string 47} 48 49func (e *InvalidEmailError) Error() string { 50 return fmt.Sprintf("invalid email address: %q", e.Email) 51} 52 53type WeakPasswordError struct { 54 Reason string 55} 56 57func (e *WeakPasswordError) Error() string { 58 return fmt.Sprintf("password does not meet strength requirements: %s", e.Reason) 59} 60 61// PDSError wraps errors from the PDS that we couldn't map to domain errors 62type PDSError struct { 63 Message string 64 StatusCode int 65} 66 67func (e *PDSError) Error() string { 68 return fmt.Sprintf("PDS error (%d): %s", e.StatusCode, e.Message) 69}