errors

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(t Type, err error) error

Types

type Domain

type Domain string

func (Domain) MarshalJSON

func (d Domain) MarshalJSON() ([]byte, error)

type Error

type Error struct {
	Err       error             `json:"-"`
	Type      Type              `json:"-"`
	Message   string            `json:"message"`
	Timestamp time.Time         `json:"-"`
	Reason    Reason            `json:"reason"`
	Domain    Domain            `json:"domain"`
	Metadata  map[string]string `json:"metadata"`
}

func NewLocal added in v0.0.4

func NewLocal(cause error, local LocalError) Error

NewLocal is a constructor to create a minimally viable Error instance given an a root cause and implementation of LocalError.

func (Error) Error

func (e Error) Error() string

func (Error) Is

func (e Error) Is(err error) bool

func (Error) WithMessage

func (e Error) WithMessage(msg string) Error

func (Error) WithMetaMap added in v0.0.4

func (e Error) WithMetaMap(data map[string]string) Error

WithMetaMap is a fluent style method to set the Metadata map on the Error instance.

func (Error) WithMetaPair added in v0.0.4

func (e Error) WithMetaPair(key, value string) Error

WithMetaPair is a fluent style convenience method to append to the Metadata map. If the Metadata map doesn't exist, it sets a new one, otherwise appends to the existing map.

func (Error) WithMetaPairs added in v0.0.4

func (e Error) WithMetaPairs(pairs ...string) Error

WithMetaPairs is a fluent style convenience method to define the Metadata map as a series of key-value pairs. Destructive, sets the Metadata field with a new Map before iterating over the parameters. This will iterate over the variadic in pairs, and take the even index as the key, and the odd index as the value, as such, an odd number of values passed will see the last value ignored.

type LocalError added in v0.0.4

type LocalError interface {
	Reason() Reason
	Type() Type
	Domain() Domain
	Message() string
}

LocalError defines the contract that allows implementing systems to define their own Reason codes

type Reason

type Reason string

func (Reason) MarshalJSON

func (r Reason) MarshalJSON() ([]byte, error)

type Type

type Type int
const (
	Unknown Type = iota
	ErrSystem
	ErrUser
	NotAuthorized
	NotFound
	RequestTimeout
	ServiceUnavailable
	BadGateway
	ErrUnhandled
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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