types

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package types provides specific error types for the errors package.

Package types provides specific error types for the errors package.

Package types provides specific error types for the errors package.

Package types provides specific error types for the errors package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppError

type AppError[T any] struct {
	// Err is the original error
	Err error

	// Message is a human-readable error message
	Message string

	// Code is a machine-readable error code
	Code string

	// Type is the error type
	Type T
}

AppError is a generic error type that can be used for different error categories.

func NewAppError

func NewAppError[T any](err error, message, code string, errorType T) *AppError[T]

NewAppError creates a new AppError.

func (*AppError[T]) Error

func (e *AppError[T]) Error() string

Error returns a string representation of the error.

func (*AppError[T]) ErrorType

func (e *AppError[T]) ErrorType() T

ErrorType returns the error type.

func (*AppError[T]) HTTPStatus

func (e *AppError[T]) HTTPStatus() int

HTTPStatus returns the HTTP status code for application errors.

func (*AppError[T]) IsApplicationError

func (e *AppError[T]) IsApplicationError() bool

IsApplicationError identifies this as an application error.

func (*AppError[T]) Unwrap

func (e *AppError[T]) Unwrap() error

Unwrap returns the original error.

type ApplicationError

type ApplicationError struct {
	// Err is the original error
	Err error

	// Message is a human-readable error message
	Message string

	// Code is a machine-readable error code
	Code string
}

ApplicationError represents an error that occurred in the application layer.

func NewApplicationError

func NewApplicationError(err error, message, code string) *ApplicationError

NewApplicationError creates a new ApplicationError.

func (*ApplicationError) Error

func (e *ApplicationError) Error() string

Error returns a string representation of the error.

func (*ApplicationError) HTTPStatus

func (e *ApplicationError) HTTPStatus() int

HTTPStatus returns the HTTP status code for application errors.

func (*ApplicationError) IsApplicationError

func (e *ApplicationError) IsApplicationError() bool

IsApplicationError identifies this as an application error.

func (*ApplicationError) Unwrap

func (e *ApplicationError) Unwrap() error

Unwrap returns the original error.

type DomainError

type DomainError struct {
	// Original is the original error
	Original error

	// Code is a machine-readable error code
	Code string

	// Message is a human-readable error message
	Message string

	// Op is the operation that caused the error
	Op string

	// Param is the parameter that caused the error
	Param string
}

DomainError represents a domain error with operation context.

func New

func New(op, code, message string, original error) *DomainError

New creates a new DomainError.

func Wrap

func Wrap(err error, op, message string) *DomainError

Wrap wraps an error with additional context.

func (*DomainError) Error

func (e *DomainError) Error() string

Error returns a string representation of the error.

func (*DomainError) HTTPStatus

func (e *DomainError) HTTPStatus() int

HTTPStatus returns the HTTP status code for domain errors.

func (*DomainError) Is

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

Is reports whether the error is of the given target type.

func (*DomainError) IsDomainError

func (e *DomainError) IsDomainError() bool

IsDomainError identifies this as a domain error.

func (*DomainError) Unwrap

func (e *DomainError) Unwrap() error

Unwrap returns the original error.

type DomainErrorType

type DomainErrorType string

DomainErrorType represents the type of domain error.

const (
	DomainErrorGeneral DomainErrorType = "DOMAIN_ERROR"
)

Domain error type constants.

type NotFoundError

type NotFoundError struct {
	// ResourceType is the type of resource that was not found
	ResourceType string

	// ID is the identifier of the resource that was not found
	ID string
}

NotFoundError represents a resource not found error.

func NewNotFoundError

func NewNotFoundError(resourceType, id string) *NotFoundError

NewNotFoundError creates a new NotFoundError.

func (*NotFoundError) Code

func (e *NotFoundError) Code() string

Code returns the not found error code.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error returns a string representation of the error.

func (*NotFoundError) HTTPStatus

func (e *NotFoundError) HTTPStatus() int

HTTPStatus returns the HTTP status code for not found errors.

func (*NotFoundError) Is

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

Is implements the errors.Is interface for NotFoundError.

func (*NotFoundError) IsNotFoundError

func (e *NotFoundError) IsNotFoundError() bool

IsNotFoundError identifies this as a not found error.

type RepositoryError

type RepositoryError struct {
	// Err is the original error
	Err error

	// Message is a human-readable error message
	Message string

	// Code is a machine-readable error code
	Code string
}

RepositoryError represents an error that occurred in the repository layer.

func NewRepositoryError

func NewRepositoryError(err error, message, code string) *RepositoryError

NewRepositoryError creates a new RepositoryError.

func (*RepositoryError) Error

func (e *RepositoryError) Error() string

Error returns a string representation of the error.

func (*RepositoryError) HTTPStatus

func (e *RepositoryError) HTTPStatus() int

HTTPStatus returns the HTTP status code for repository errors.

func (*RepositoryError) IsRepositoryError

func (e *RepositoryError) IsRepositoryError() bool

IsRepositoryError identifies this as a repository error.

func (*RepositoryError) Unwrap

func (e *RepositoryError) Unwrap() error

Unwrap returns the original error.

type ValidationError

type ValidationError struct {
	// Msg is the error message
	Msg string

	// Field is the name of the field that failed validation
	Field string
}

ValidationError represents a validation error for a specific field.

func NewFieldValidationError

func NewFieldValidationError(msg, field string) *ValidationError

NewFieldValidationError creates a new ValidationError with a message and field name.

func NewValidationError

func NewValidationError(msg string) *ValidationError

NewValidationError creates a new ValidationError with a message.

func (*ValidationError) Code

func (e *ValidationError) Code() string

Code returns the validation error code.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error returns a string representation of the validation error.

func (*ValidationError) HTTPStatus

func (e *ValidationError) HTTPStatus() int

HTTPStatus returns the HTTP status code for validation errors.

func (*ValidationError) IsValidationError

func (e *ValidationError) IsValidationError() bool

IsValidationError identifies this as a validation error.

type ValidationErrors

type ValidationErrors struct {
	// Errors is a slice of validation errors
	Errors []*ValidationError
}

ValidationErrors represents multiple validation errors.

func NewValidationErrors

func NewValidationErrors(errors ...*ValidationError) *ValidationErrors

NewValidationErrors creates a new ValidationErrors with the provided errors.

func (*ValidationErrors) AddError

func (e *ValidationErrors) AddError(err *ValidationError)

AddError adds a validation error to the collection.

func (*ValidationErrors) Code

func (e *ValidationErrors) Code() string

Code returns the validation error code.

func (*ValidationErrors) Error

func (e *ValidationErrors) Error() string

Error returns a string representation of all validation errors.

func (*ValidationErrors) HTTPStatus

func (e *ValidationErrors) HTTPStatus() int

HTTPStatus returns the HTTP status code for validation errors.

func (*ValidationErrors) HasErrors

func (e *ValidationErrors) HasErrors() bool

HasErrors returns true if there are any validation errors.

func (*ValidationErrors) IsValidationError

func (e *ValidationErrors) IsValidationError() bool

IsValidationError identifies this as a validation error.

Jump to

Keyboard shortcuts

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