fault

package
v0.0.0-...-d267593 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package fault defines stable application errors without exposing internal causes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category is the class of an Error; it selects the default HTTP status.

const (
	CategoryInvalid      Category = "invalid"
	CategoryUnauthorized Category = "unauthorized"
	CategoryForbidden    Category = "forbidden"
	CategoryNotFound     Category = "not_found"
	CategoryConflict     Category = "conflict"
	CategoryUnavailable  Category = "unavailable"
	CategoryRateLimited  Category = "rate_limited"
	CategoryInternal     Category = "internal"
)

The categories of Error and their default HTTP statuses: 400, 401, 403, 404, 409, 503, 429 and 500.

type Error

type Error struct {
	Code       string
	Message    string
	Category   Category
	Cause      error
	Metadata   map[string]string
	Retryable  bool
	HTTPStatus int
}

Error is a stable application error: a machine-readable Code and a safe Message for clients, with an optional Cause and Metadata that stay internal.

func From

func From(err error) *Error

From returns the first *Error in err's chain, or nil.

func New

func New(code, message string, category Category, status int) *Error

New returns an Error. A status of 0 selects the default for the category.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

Is matches another *Error with the same Code, so errors.Is recognizes a sentinel even after WithCause or Metadata produced a copy of it.

func (*Error) Status

func (e *Error) Status() int

Status returns the HTTP status for the error: the explicit HTTPStatus when set, otherwise the default for its category.

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithCause

func (e *Error) WithCause(cause error) *Error

WithCause returns a copy of e with cause set; e itself is unchanged.

Jump to

Keyboard shortcuts

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