errors

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 38

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")
	ErrTimeout            = errors.New("timeout")
	ErrIdleTimeout        = errors.New("idle timeout")
	ErrNothingRead        = errors.New("nothing read")
	ErrShortConnection    = errors.New("short connection")
	ErrNoFreeConns        = errors.New("no free connections available to host")
	ErrConnectionClosed   = errors.New("connection closed")
	ErrNotSupportProtocol = errors.New("not support protocol")
	ErrNoMultipartForm    = errors.New("request has no multipart/form-data Content-Type")
	ErrBadPoolConn        = errors.New("connection is closed by peer while being in the connection pool")
)

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 NewPrivatef added in v0.4.0

func NewPrivatef(format string, v ...interface{}) *Error

func NewPublic

func NewPublic(err string) *Error

shortcut for creating a public *Error from string

func NewPublicf added in v0.4.0

func NewPublicf(format string, v ...interface{}) *Error

func Newf added in v0.4.0

func Newf(t ErrorType, meta interface{}, format string, v ...interface{}) *Error

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