Documentation
¶
Overview ¶
Package errors provides safe application errors interoperable with standard Go errors.
Index ¶
- func As(err error, target any) bool
- func Is(err, target error) bool
- func Recover(dst *error, report func(error))
- func Unwrap(err error) error
- type AppError
- type Category
- type Option
- func WithCategory(v Category) Option
- func WithCause(v error) Option
- func WithCode(v string) Option
- func WithDebug(v string) Option
- func WithDetails(v map[string]any) Option
- func WithHTTPStatus(v int) Option
- func WithMessage(v string) Option
- func WithRetryAfter(v time.Duration) Option
- func WithRetryable(v bool) Option
- func WithSeverity(v Severity) Option
- type Severity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppError ¶
type AppError struct {
Code string `json:"code"`
Message string `json:"message"`
DebugMessage string `json:"-"`
Category Category `json:"category"`
Severity Severity `json:"severity"`
HTTPStatus int `json:"-"`
Details map[string]any `json:"details,omitempty"`
Cause error `json:"-"`
Retryable bool `json:"retryable,omitempty"`
RetryAfter time.Duration `json:"-"`
TraceID string `json:"trace_id,omitempty"`
CorrelationID string `json:"correlation_id,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
AppError separates public data from private diagnostics. Details and Metadata must contain only caller-approved public data.
func New ¶
New constructs and validates an explicitly owned instance. See package documentation for defaults and cleanup.
type Category ¶
type Category string
Category classifies an application failure.
const ( Validation Category = "VALIDATION" Authentication Category = "AUTHENTICATION" Authorization Category = "AUTHORIZATION" Business Category = "BUSINESS" NotFound Category = "NOT_FOUND" Conflict Category = "CONFLICT" RateLimit Category = "RATE_LIMIT" Database Category = "DATABASE" Cache Category = "CACHE" Messaging Category = "MESSAGING" Network Category = "NETWORK" Infrastructure Category = "INFRASTRUCTURE" Internal Category = "INTERNAL" Timeout Category = "TIMEOUT" )
type Option ¶
type Option func(*AppError)
Option configures a newly constructed application error.
func WithCategory ¶
WithCategory sets the application error category.
func WithDetails ¶
WithDetails sets explicitly approved public validation details.
func WithHTTPStatus ¶
WithHTTPStatus sets the intended HTTP status.
func WithMessage ¶
WithMessage sets an approved customer-facing message.
func WithRetryAfter ¶
WithRetryAfter sets retry delay metadata.
func WithRetryable ¶
WithRetryable sets retryability metadata without performing retries.
func WithSeverity ¶
WithSeverity sets the application error severity.