errors

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCode

func IsCode(err error, code Code) bool

IsCode checks if error or its chain has the given code

Types

type AppError

type AppError struct {
	Code    Code                   `json:"code"`
	Message string                 `json:"message"`
	Cause   error                  `json:"-"`
	Fields  map[string]interface{} `json:"fields,omitempty"`
}

AppError is the unified error type used across the repository

func Conflict

func Conflict(message string, cause error) *AppError

func Dependency

func Dependency(message string, cause error) *AppError

func Forbidden

func Forbidden(message string, cause error) *AppError

func Internal

func Internal(message string, cause error) *AppError

Helpers for common errors

func InvalidInput

func InvalidInput(message string, cause error) *AppError

func New

func New(code Code, message string) *AppError

New creates a new AppError

func NotFound

func NotFound(message string, cause error) *AppError

func Timeout

func Timeout(message string, cause error) *AppError

func Unauthorized

func Unauthorized(message string, cause error) *AppError

func Unavailable

func Unavailable(message string, cause error) *AppError

func Validation

func Validation(message string, cause error) *AppError

func Wrap

func Wrap(err error, code Code, message string) *AppError

Wrap wraps an error into AppError with a code and message

func (*AppError) AddField

func (e *AppError) AddField(key string, value interface{}) *AppError

AddField adds a field to the error metadata

func (*AppError) Error

func (e *AppError) Error() string

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

type Code

type Code string

Code represents a standardized error code across libraries

const (
	CodeInternal     Code = "INTERNAL"
	CodeInvalidInput Code = "INVALID_INPUT"
	CodeNotFound     Code = "NOT_FOUND"
	CodeConflict     Code = "CONFLICT"
	CodeUnauthorized Code = "UNAUTHORIZED"
	CodeForbidden    Code = "FORBIDDEN"
	CodeTimeout      Code = "TIMEOUT"
	CodeUnavailable  Code = "UNAVAILABLE"
	CodeDependency   Code = "DEPENDENCY_ERROR"
	CodeValidation   Code = "VALIDATION_ERROR"
)

Jump to

Keyboard shortcuts

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