A community based topic aggregation platform built on atproto
at main 1.5 kB view raw
1package errors 2 3import ( 4 "errors" 5 "fmt" 6) 7 8var ( 9 ErrNotFound = errors.New("resource not found") 10 ErrAlreadyExists = errors.New("resource already exists") 11 ErrInvalidInput = errors.New("invalid input") 12 ErrUnauthorized = errors.New("unauthorized") 13 ErrForbidden = errors.New("forbidden") 14 ErrInternal = errors.New("internal server error") 15 ErrDatabaseError = errors.New("database error") 16 ErrValidationFailed = errors.New("validation failed") 17) 18 19type ValidationError struct { 20 Field string 21 Message string 22} 23 24func (e ValidationError) Error() string { 25 return fmt.Sprintf("validation error on field '%s': %s", e.Field, e.Message) 26} 27 28type ConflictError struct { 29 Resource string 30 Field string 31 Value string 32} 33 34func (e ConflictError) Error() string { 35 return fmt.Sprintf("%s with %s '%s' already exists", e.Resource, e.Field, e.Value) 36} 37 38type NotFoundError struct { 39 ID interface{} 40 Resource string 41} 42 43func (e NotFoundError) Error() string { 44 return fmt.Sprintf("%s with ID '%v' not found", e.Resource, e.ID) 45} 46 47func NewValidationError(field, message string) error { 48 return ValidationError{ 49 Field: field, 50 Message: message, 51 } 52} 53 54func NewConflictError(resource, field, value string) error { 55 return ConflictError{ 56 Resource: resource, 57 Field: field, 58 Value: value, 59 } 60} 61 62func NewNotFoundError(resource string, id interface{}) error { 63 return NotFoundError{ 64 Resource: resource, 65 ID: id, 66 } 67}