errors

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnauthorizedError = NewErrorCode("unauthorized", http.StatusUnauthorized)

Functions

func IsDomainError

func IsDomainError(err error, kind ...ErrorKind) bool

IsDomainError checks if an error is a DomainError and optionally matches a specific kind

func NewCompoundError

func NewCompoundError(summary string, errs ...error) error

func ToHTTPStatus

func ToHTTPStatus(err error) int

ToHTTPStatus maps an error to an HTTP status code. This should ONLY be called at the controller/transport layer.

Types

type CompoundError

type CompoundError struct {
	Errs []error
	// contains filtered or unexported fields
}

func (*CompoundError) Error

func (c *CompoundError) Error() string

type DomainError

type DomainError struct {
	Kind    ErrorKind
	Message string
	Cause   error
}

DomainError represents a business logic error without HTTP coupling. Services and repositories should return DomainErrors instead of ErrorCode to maintain proper layer separation.

func Conflict

func Conflict(msg string) *DomainError

Conflict creates a conflict error (maps to 409 Conflict)

func Conflictf

func Conflictf(format string, args ...interface{}) *DomainError

Conflictf creates a conflict error with formatted message

func Forbidden

func Forbidden(msg string) *DomainError

Forbidden creates a forbidden error (maps to 403 Forbidden)

func Internal

func Internal(msg string, cause error) *DomainError

Internal creates an internal error (maps to 500 Internal Server Error)

func Internalf

func Internalf(cause error, format string, args ...interface{}) *DomainError

Internalf creates an internal error with formatted message

func NotFound

func NotFound(resource, id string) *DomainError

NotFound creates a not found error (maps to 404 Not Found)

func NotFoundMsg

func NotFoundMsg(msg string) *DomainError

NotFoundMsg creates a not found error with custom message

func Unauthorized

func Unauthorized(msg string) *DomainError

Unauthorized creates an unauthorized error (maps to 401 Unauthorized)

func Unavailable

func Unavailable(msg string) *DomainError

Unavailable creates an unavailable error (maps to 503 Service Unavailable)

func Validation

func Validation(msg string) *DomainError

Validation creates a validation error (maps to 400 Bad Request)

func Validationf

func Validationf(format string, args ...interface{}) *DomainError

Validationf creates a validation error with formatted message

func (*DomainError) Error

func (e *DomainError) Error() string

func (*DomainError) Unwrap

func (e *DomainError) Unwrap() error

type ErrorCode

type ErrorCode interface {
	error
	Code() int
}

func NewErrorCode

func NewErrorCode(message string, code int) ErrorCode

func ToErrorCode

func ToErrorCode(err error) ErrorCode

ToErrorCode converts any error to an ErrorCode for HTTP response serialization. This should ONLY be called at the controller/transport layer.

type ErrorKind

type ErrorKind string

ErrorKind represents the semantic category of an error (no HTTP concepts)

const (
	ErrKindValidation   ErrorKind = "validation"
	ErrKindNotFound     ErrorKind = "not_found"
	ErrKindConflict     ErrorKind = "conflict"
	ErrKindUnauthorized ErrorKind = "unauthorized"
	ErrKindForbidden    ErrorKind = "forbidden"
	ErrKindInternal     ErrorKind = "internal"
	ErrKindUnavailable  ErrorKind = "unavailable"
)

Jump to

Keyboard shortcuts

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