errors

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 4 Imported by: 31

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// These errors are the base error, which are used for checking in errors.Is()
	ErrNeedMore        = errors.New("need more data")
	ErrChunkedStream   = errors.New("chunked stream")
	ErrBodyTooLarge    = errors.New("body size exceeds the given limit")
	ErrHijacked        = errors.New("connection has been hijacked")
	ErrIdleTimeout     = errors.New("idle timeout")
	ErrTimeout         = errors.New("timeout")
	ErrNothingRead     = errors.New("nothing read")
	ErrShortConnection = errors.New("short connection")
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Err  error
	Type ErrorType
	Meta interface{}
}

func New

func New(err error, t ErrorType, meta interface{}) *Error

func NewPrivate

func NewPrivate(err string) *Error

func NewPublic

func NewPublic(err string) *Error

shortcut for creating a public *Error from string

func (*Error) Error

func (msg *Error) Error() string

AbortWithMsg implements the error interface.

func (*Error) IsType

func (msg *Error) IsType(flags ErrorType) bool

IsType judges one error.

func (*Error) JSON

func (msg *Error) JSON() interface{}

JSON creates a properly formatted JSON

func (*Error) SetMeta

func (msg *Error) SetMeta(data interface{}) *Error

SetMeta sets the error's meta data.

func (*Error) SetType

func (msg *Error) SetType(flags ErrorType) *Error

SetType sets the error's type.

func (*Error) Unwrap

func (msg *Error) Unwrap() error

type ErrorChain

type ErrorChain []*Error

func (ErrorChain) ByType

func (a ErrorChain) ByType(typ ErrorType) ErrorChain

ByType returns a readonly copy filtered the byte. ie ByType(hertz.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic.

func (ErrorChain) Errors

func (a ErrorChain) Errors() []string

Errors returns an array will all the error messages. Example:

c.Error(errors.New("first"))
c.Error(errors.New("second"))
c.Error(errors.New("third"))
c.Errors.Errors() // == []string{"first", "second", "third"}

func (ErrorChain) JSON

func (a ErrorChain) JSON() interface{}

func (ErrorChain) Last

func (a ErrorChain) Last() *Error

Last returns the last error in the slice. It returns nil if the array is empty. Shortcut for errors[len(errors)-1].

func (ErrorChain) String

func (a ErrorChain) String() string

type ErrorType

type ErrorType uint64

ErrorType is an unsigned 64-bit error code as defined in the hertz spec.

const (
	// ErrorTypeBind is used when Context.Bind() fails.
	ErrorTypeBind ErrorType = 1 << iota
	// ErrorTypeRender is used when Context.Render() fails.
	ErrorTypeRender
	// ErrorTypePrivate indicates a private error.
	ErrorTypePrivate
	// ErrorTypePublic indicates a public error.
	ErrorTypePublic
	// ErrorTypeAny indicates any other error.
	ErrorTypeAny
)

Jump to

Keyboard shortcuts

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