errors

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cancaled = NewCategory("Cancelled", 499) // non-standard status code for cancellation

	BadRequest       = NewCategory("BadRequest", http.StatusBadRequest)
	InvalidArgument  = NewCategory("InvalidArgument", http.StatusBadRequest)
	Unauthorized     = NewCategory("Unauthorized", http.StatusUnauthorized)
	Forbidden        = NewCategory("Forbidden", http.StatusForbidden)
	PermissionDenied = NewCategory("PermissionDenied", http.StatusForbidden)
	NotFound         = NewCategory("NotFound", http.StatusNotFound)
	DeadlineExceeded = NewCategory("DeadlineExceeded", http.StatusRequestTimeout)
	Conflict         = NewCategory("Conflict", http.StatusConflict)
	AlreadyExist     = NewCategory("AlreadyExist", http.StatusConflict)
	TooManyRequests  = NewCategory("TooManyRequests", http.StatusTooManyRequests)

	Internal          = NewCategory("Internal", http.StatusInternalServerError)
	NotImplemented    = NewCategory("NotImplemented", http.StatusNotImplemented)
	Unavailable       = NewCategory("Unavailable", http.StatusServiceUnavailable)
	ResourceExhausted = NewCategory("ResourceExhausted", http.StatusServiceUnavailable)

	DBFailed = NewCategory("DBFailed", http.StatusInternalServerError)
)

Functions

func Combine

func Combine(errors ...error) error

func Has

func Has(err error, cause error) bool

func Is

func Is(err error, c Category) bool

func Message

func Message(err error) string

func New

func New(opts ...Option) error

func Newf

func Newf(format string, args ...any) error

func Wrap

func Wrap(err error, opts ...Option) error

func Wrapf

func Wrapf(err error, format string, args ...any) error

Types

type Base

type Base interface {
	Message() string // latest error message without cause
	Error() string
	Format(f fmt.State, c rune)
	Code() (string, labels.Set)
	Category() Category
	Has(cause error) bool
	Cause() error
	RootCause() error
}

type Category

type Category interface {
	Error() string
	StatusCode() int
	New(opts ...Option) error
	Newf(format string, args ...any) error
	Wrap(err error, opts ...Option) error
	Wrapf(err error, format string, args ...any) error
}

func NewCategory

func NewCategory(description string, status int) Category

type Option

type Option func(*errBase)

func WithCategory

func WithCategory(category Category) Option

func WithCode

func WithCode(code string, details map[string]string) Option

func WithFormat

func WithFormat(format string, args ...any) Option

Jump to

Keyboard shortcuts

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