A community based topic aggregation platform built on atproto
at main 40 lines 1.6 kB view raw
1package pds 2 3import "errors" 4 5// Typed errors for PDS operations. 6// These allow services to use errors.Is() for reliable error detection 7// instead of fragile string matching. 8var ( 9 // ErrUnauthorized indicates the request failed due to invalid or expired credentials (HTTP 401). 10 ErrUnauthorized = errors.New("unauthorized") 11 12 // ErrForbidden indicates the request was rejected due to insufficient permissions (HTTP 403). 13 ErrForbidden = errors.New("forbidden") 14 15 // ErrNotFound indicates the requested resource does not exist (HTTP 404). 16 ErrNotFound = errors.New("not found") 17 18 // ErrBadRequest indicates the request was malformed or invalid (HTTP 400). 19 ErrBadRequest = errors.New("bad request") 20 21 // ErrConflict indicates a conflict occurred, such as a record being modified by another operation (HTTP 409). 22 ErrConflict = errors.New("conflict") 23 24 // ErrRateLimited indicates the request was rejected due to rate limiting (HTTP 429). 25 ErrRateLimited = errors.New("rate limited") 26 27 // ErrPayloadTooLarge indicates the request payload exceeds PDS limits (HTTP 413). 28 ErrPayloadTooLarge = errors.New("payload too large") 29) 30 31// IsAuthError returns true if the error is an authentication/authorization error. 32// This is a convenience function for checking if re-authentication might help. 33func IsAuthError(err error) bool { 34 return errors.Is(err, ErrUnauthorized) || errors.Is(err, ErrForbidden) 35} 36 37// IsConflictError returns true if the error indicates a conflict (e.g., duplicate record). 38func IsConflictError(err error) bool { 39 return errors.Is(err, ErrConflict) 40}