errors

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidation    = New(ErrCodeValidation, "validation error")
	ErrRequiredField = New(ErrCodeRequiredField, "field is required")
	ErrInvalidFormat = New(ErrCodeInvalidFormat, "invalid format")
	ErrInvalidValue  = New(ErrCodeInvalidValue, "invalid value")
)

Validation errors

View Source
var (
	ErrUnauthorized   = New(ErrCodeUnauthorized, "unauthorized")
	ErrInvalidToken   = New(ErrCodeInvalidToken, "invalid token")
	ErrTokenExpired   = New(ErrCodeTokenExpired, "token expired")
	ErrAuthentication = New(ErrCodeAuthentication, "authentication error")
)

Authentication errors

View Source
var (
	ErrForbidden        = New(ErrCodeForbidden, "forbidden")
	ErrInsufficientRole = New(ErrCodeInsufficientRole, "insufficient role")
)

Authorization errors

View Source
var (
	ErrNotFound      = New(ErrCodeNotFound, "resource not found")
	ErrAlreadyExists = New(ErrCodeAlreadyExists, "resource already exists")
	ErrConflict      = New(ErrCodeConflict, "resource conflict")
)

Resource errors

View Source
var (
	ErrInternal = New(ErrCodeInternal, "internal error")
	ErrDatabase = New(ErrCodeDatabase, "database error")
	ErrTimeout  = New(ErrCodeTimeout, "operation timed out")
)

System errors

Functions

This section is empty.

Types

type DomainError

type DomainError struct {
	Code    ErrorCode
	Message string
	Err     error
	Context map[string]any
}

DomainError represents a domain-specific error

func New

func New(code ErrorCode, message string) *DomainError

New creates a new domain error

func Wrap

func Wrap(err error, code ErrorCode, message string) *DomainError

Wrap wraps an existing error with domain context

func (*DomainError) Error

func (e *DomainError) Error() string

Error implements the error interface

func (*DomainError) Is

func (e *DomainError) Is(target error) bool

Is checks if the error is of a specific type

func (*DomainError) Unwrap

func (e *DomainError) Unwrap() error

Unwrap returns the underlying error

func (*DomainError) WithContext

func (e *DomainError) WithContext(key string, value any) *DomainError

WithContext adds context to the error

type ErrorCode

type ErrorCode string

ErrorCode represents a unique error code for each error type

const (
	// ErrCodeValidation represents a general validation error
	ErrCodeValidation ErrorCode = "VALIDATION_ERROR"
	// ErrCodeRequiredField represents a required field validation error
	ErrCodeRequiredField ErrorCode = "REQUIRED_FIELD"
	// ErrCodeInvalidFormat represents an invalid format error
	ErrCodeInvalidFormat ErrorCode = "INVALID_FORMAT"
	// ErrCodeInvalidValue represents an invalid value error
	ErrCodeInvalidValue ErrorCode = "INVALID_VALUE"

	// ErrCodeUnauthorized represents an unauthorized access error
	ErrCodeUnauthorized ErrorCode = "UNAUTHORIZED"
	// ErrCodeInvalidToken represents an invalid token error
	ErrCodeInvalidToken ErrorCode = "INVALID_TOKEN"
	// ErrCodeTokenExpired represents a token expiration error
	ErrCodeTokenExpired ErrorCode = "TOKEN_EXPIRED"
	// ErrCodeAuthentication represents a general authentication error
	ErrCodeAuthentication ErrorCode = "AUTHENTICATION_ERROR"

	// ErrCodeForbidden represents a forbidden access error
	ErrCodeForbidden ErrorCode = "FORBIDDEN"
	// ErrCodeInsufficientRole represents an insufficient role error
	ErrCodeInsufficientRole ErrorCode = "INSUFFICIENT_ROLE"

	// ErrCodeNotFound represents a resource not found error
	ErrCodeNotFound ErrorCode = "NOT_FOUND"
	// ErrCodeAlreadyExists represents a resource already exists error
	ErrCodeAlreadyExists ErrorCode = "ALREADY_EXISTS"
	// ErrCodeConflict represents a resource conflict error
	ErrCodeConflict ErrorCode = "CONFLICT"

	// ErrCodeInternal represents an internal server error
	ErrCodeInternal ErrorCode = "INTERNAL_ERROR"
	// ErrCodeDatabase represents a database error
	ErrCodeDatabase ErrorCode = "DATABASE_ERROR"
	// ErrCodeTimeout represents an operation timeout error
	ErrCodeTimeout ErrorCode = "TIMEOUT"

	// ErrCodeInvalidInput represents an invalid input error
	ErrCodeInvalidInput ErrorCode = "INVALID_INPUT"
)

Jump to

Keyboard shortcuts

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