errors

package
v0.0.0-...-3399c5e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrRequired indicates a required field is missing
	ErrRequired = ErrorCode("REQUIRED")

	// ErrInvalid indicates an invalid value for a field
	ErrInvalid = ErrorCode("INVALID")

	// ErrDuplicate indicates a duplicate value for a field
	ErrDuplicate = ErrorCode("DUPLICATE")

	// ErrNotFound indicates a resource that was not found
	ErrNotFound = ErrorCode("NOT_FOUND")

	// ErrBusinessLogic indicates a business logic error
	ErrBusinessLogic = ErrorCode("BUSINESS_LOGIC")

	// ErrUnauthorized indicates an unauthorized request
	ErrUnauthorized = ErrorCode("UNAUTHORIZED")

	// ErrForbidden indicates a forbidden request
	ErrForbidden = ErrorCode("FORBIDDEN")

	// ErrInvalidFormat indicates an invalid format for a field
	ErrInvalidFormat = ErrorCode("INVALID_FORMAT")

	// ErrInvalidLength indicates an invalid length for a field
	ErrInvalidLength = ErrorCode("INVALID_LENGTH")

	// ErrInvalidReference indicates an invalid reference for a field
	ErrInvalidReference = ErrorCode("INVALID_REFERENCE")

	// ErrInvalidOperation indicates an invalid operation for a field
	ErrInvalidOperation = ErrorCode("INVALID_OPERATION")

	// ErrSystemError indicates a system error
	ErrSystemError = ErrorCode("SYSTEM_ERROR")

	// ErrAlreadyExists indicates a resource that already exists
	ErrAlreadyExists = ErrorCode("ALREADY_EXISTS")

	// ErrAlreadyCleared indicates a resource that has already been cleared
	// This is primarily used when a resource is being deleted and the user is trying to delete it again
	ErrAlreadyCleared = ErrorCode("ALREADY_CLEARED")

	// ErrVersionMismatch indicates a version mismatch between requested and current version
	ErrVersionMismatch = ErrorCode("VERSION_MISMATCH")

	// ErrTooManyRequests indicates too many requests are being sent within a short period of time
	ErrTooManyRequests = ErrorCode("TOO_MANY_REQUESTS")

	// ErrComplianceViolation indicates a violation of a CFR
	ErrComplianceViolation = ErrorCode("COMPLIANCE_VIOLATION")
)

Variables

This section is empty.

Functions

func FromOzzoErrors

func FromOzzoErrors(valErrors val.Errors, multiErr *MultiError)

func FromValidationErrors deprecated

func FromValidationErrors(valErrors val.Errors, multiErr *MultiError, prefix string)

Deprecated: Use FromOzzoErrors instead.

func IsAuthenticationError

func IsAuthenticationError(err error) bool

func IsAuthorizationError

func IsAuthorizationError(err error) bool

func IsBusinessError

func IsBusinessError(err error) bool

func IsDatabaseError

func IsDatabaseError(err error) bool

func IsError

func IsError(err error) bool

func IsMultiError

func IsMultiError(err error) bool

func IsNotFoundError

func IsNotFoundError(err error) bool

func IsRateLimitError

func IsRateLimitError(err error) bool

Types

type AuthenticationError

type AuthenticationError struct {
	Code     ErrorCode `json:"code"`
	Message  string    `json:"message"`
	Internal error     `json:"-"`
}

func NewAuthenticationError

func NewAuthenticationError(message string) *AuthenticationError

func (*AuthenticationError) Error

func (e *AuthenticationError) Error() string

func (*AuthenticationError) WithInternal

func (e *AuthenticationError) WithInternal(err error) *AuthenticationError

type AuthorizationError

type AuthorizationError struct {
	Code     ErrorCode `json:"code"`
	Message  string    `json:"message"`
	Internal error     `json:"-"`
}

func NewAuthorizationError

func NewAuthorizationError(message string) *AuthorizationError

func (*AuthorizationError) Error

func (e *AuthorizationError) Error() string

func (*AuthorizationError) WithInternal

func (e *AuthorizationError) WithInternal(err error) *AuthorizationError

type BusinessError

type BusinessError struct {
	Code     ErrorCode         `json:"code"`
	Message  string            `json:"message"`
	Details  string            `json:"details,omitempty"`
	Params   map[string]string `json:"params,omitempty"`
	Internal error             `json:"-"`
}

func NewBusinessError

func NewBusinessError(message string) *BusinessError

func (*BusinessError) Error

func (e *BusinessError) Error() string

func (*BusinessError) WithInternal

func (e *BusinessError) WithInternal(err error) *BusinessError

func (*BusinessError) WithParam

func (e *BusinessError) WithParam(key, value string) *BusinessError

type DatabaseError

type DatabaseError struct {
	Code     ErrorCode `json:"code"`
	Message  string    `json:"message"`
	Internal error     `json:"-"`
}

func NewDatabaseError

func NewDatabaseError(message string) *DatabaseError

func (*DatabaseError) Error

func (e *DatabaseError) Error() string

func (*DatabaseError) WithInternal

func (e *DatabaseError) WithInternal(err error) *DatabaseError

type Error

type Error struct {
	Field    string    `json:"field"`
	Code     ErrorCode `json:"code"`
	Message  string    `json:"message"`
	Internal error     `json:"-"`
}

Error represents a single validation error

func NewValidationError

func NewValidationError(field string, code ErrorCode, message string) *Error

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

type ErrorCode

type ErrorCode string

func InferErrorCode

func InferErrorCode(err error) ErrorCode

type MultiError

type MultiError struct {
	Errors []*Error `json:"errors"`
	// contains filtered or unexported fields
}

func NewMultiError

func NewMultiError() *MultiError

func (*MultiError) Add

func (m *MultiError) Add(field string, code ErrorCode, message string)

Add adds a new validation error to the collection

func (*MultiError) AddError

func (m *MultiError) AddError(err *Error)

AddError adds an existing Error to the collection with proper prefix handling

func (*MultiError) Error

func (m *MultiError) Error() string

Error implements the error interface

func (*MultiError) HasErrors

func (m *MultiError) HasErrors() bool

HasErrors returns true if there are any validation errors

func (*MultiError) MarshalJSON

func (m *MultiError) MarshalJSON() ([]byte, error)

func (*MultiError) ToJSON

func (m *MultiError) ToJSON() string

func (*MultiError) WithIndex

func (m *MultiError) WithIndex(prefix string, idx int) *MultiError

func (*MultiError) WithPrefix

func (m *MultiError) WithPrefix(prefix string) *MultiError

type NotFoundError

type NotFoundError struct {
	Code     ErrorCode `json:"code"`
	Message  string    `json:"message"`
	Internal error     `json:"-"`
}

func NewNotFoundError

func NewNotFoundError(message string) *NotFoundError

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type RateLimitError

type RateLimitError struct {
	Field    string    `json:"field,omitempty"`
	Code     ErrorCode `json:"code"`
	Message  string    `json:"message"`
	Internal error     `json:"-"`
}

func NewRateLimitError

func NewRateLimitError(field string, message string) *RateLimitError

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

func (*RateLimitError) WithInternal

func (e *RateLimitError) WithInternal(err error) *RateLimitError

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL