errors

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf with stack trace and formatted message

func IsStatus

func IsStatus(err error) bool

IsStatus returns true if err is a Status

func New

func New(message string) error

New error with stack trace

func StatusCode

func StatusCode(err error) int

StatusCode returns the Status code if err is a Status, zero if err is not a Status

func Wrap

func Wrap(err error, message string) error

Wrap error with new message

If err is a Status, it will not be wrapped

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf error with new formatted message

If err is a Status, it will not be wrapped

Types

type Item added in v0.6.0

type Item struct {
	Field   string `json:"field,omitempty"`
	Message string `json:"message"`
}

type Status

type Status struct {
	At      string
	Cause   error
	Code    int
	Message string
	Items   []Item
}

Status data model

Implements error interface

func NewStatus

func NewStatus(code int, message string) Status

NewStatus with code and message

func NewStatusWithCause added in v0.10.0

func NewStatusWithCause(cause error, code int, message string) Status

NewStatus with cause, code, and message

Cause can be useful to record an error that caused a Status to be created

func NewStatusWithItems added in v0.6.0

func NewStatusWithItems(code int, message string, items []Item) Status

NewStatusWithItems with code, message, and items

Items can be useful to add extra context to the error

func Statusf

func Statusf(code int, format string, args ...interface{}) Status

Statusf with code and formatted message

func (Status) Error

func (s Status) Error() string

Error so that Status objects can be treated as errors

func (Status) MarshalJSON added in v0.12.0

func (s Status) MarshalJSON() ([]byte, error)

func (Status) RenderItems added in v0.6.0

func (s Status) RenderItems() []byte

Render items

Jump to

Keyboard shortcuts

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