errors

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package errors defines typed application errors used for consistent API responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppError

type AppError struct {
	// Code is stable machine-readable identifier.
	Code Code
	// Message is client-facing summary.
	Message string
	// StatusCode is HTTP status to write for this error.
	StatusCode int
	// Details is optional structured payload.
	Details any
	// Cause stores underlying internal error.
	Cause error
}

AppError is the typed error model used across handlers and policies.

func AsAppError

func AsAppError(err error) (*AppError, bool)

AsAppError extracts AppError from wrapped error chain.

func New

func New(code Code, status int, msg string) *AppError

New constructs an AppError with code, status, and message.

func WithCause

func WithCause(err *AppError, cause error) *AppError

WithCause attaches underlying cause to AppError.

func WithDetails

func WithDetails(err *AppError, details any) *AppError

WithDetails attaches structured details payload to AppError.

func (*AppError) Error

func (e *AppError) Error() string

Error implements error interface.

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns underlying cause for errors.Is/errors.As support.

type Code

type Code string

Code is a stable machine-readable API error identifier.

const (
	// CodeInternal represents unexpected internal failures.
	CodeInternal Code = "internal_error"
	// CodeBadRequest represents invalid client input.
	CodeBadRequest Code = "bad_request"
	// CodeUnsupportedMedia represents unsupported request content type.
	CodeUnsupportedMedia Code = "unsupported_media_type"
	// CodeNotFound represents missing resources.
	CodeNotFound Code = "not_found"
	// CodeMethodNotAllowed represents unsupported HTTP method.
	CodeMethodNotAllowed Code = "method_not_allowed"
	// CodeUnauthorized represents authentication failures.
	CodeUnauthorized Code = "unauthorized"
	// CodeForbidden represents authorization failures.
	CodeForbidden Code = "forbidden"
	// CodeTooManyRequests represents rate limit exhaustion.
	CodeTooManyRequests Code = "too_many_requests"
	// CodeConflict represents state conflicts.
	CodeConflict Code = "conflict"
	// CodeTimeout represents request timeout failures.
	CodeTimeout Code = "timeout"
	// CodeDependencyFailure represents unavailable dependency failures.
	CodeDependencyFailure Code = "dependency_unavailable"
)

Jump to

Keyboard shortcuts

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