errors

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides unified error definitions for API layer.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig is returned when config is nil or invalid.
	ErrInvalidConfig = errors.New("invalid config")

	// ErrInvalidArgument is returned when an argument is invalid.
	ErrInvalidArgument = errors.New("invalid argument")

	// ErrNotFound is returned when a resource is not found.
	ErrNotFound = errors.New("resource not found")

	// ErrAlreadyExists is returned when a resource already exists.
	ErrAlreadyExists = errors.New("resource already exists")

	// ErrAccessDenied is returned when access to a resource is denied.
	ErrAccessDenied = errors.New("access denied")

	// ErrTimeout is returned when an operation times out.
	ErrTimeout = errors.New("operation timeout")

	// ErrInternal is returned for internal server errors.
	ErrInternal = errors.New("internal server error")

	// ErrNotImplemented is returned when a feature is not implemented.
	ErrNotImplemented = errors.New("feature not implemented")
)

Functions

func Wrap

func Wrap(err error, message string) error

Wrap wraps an error with additional context. Args: err - the error to wrap. message - additional message. Returns wrapped error.

Types

type AppError

type AppError struct {
	// Code is the error code.
	Code string
	// Message is the error message.
	Message string
	// Err is the underlying error.
	Err error
	// Context is additional context.
	Context map[string]interface{}
}

AppError represents an application error with additional context.

func NewAppError

func NewAppError(code, message string, err error) *AppError

NewAppError creates a new application error. Args: code - error code. message - error message. err - underlying error. Returns new application error.

func (*AppError) Error

func (e *AppError) Error() string

Error implements the error interface.

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns the underlying error.

func (*AppError) WithContext

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

WithContext adds context to the error. Args: key - context key. value - context value. Returns the error for chaining.

Jump to

Keyboard shortcuts

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