errors

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownCode = 100000
	// UnknownCode is unknown code for error info.
	UnknownStatus = 500
	// UnknownReason is unknown reason for error info.
	UnknownReason = ""
	// SupportPackageIsVersion1 this constant should not be referenced by any other code.
	SupportPackageIsVersion1 = true
)
View Source
const (

	// StatusClientClosed is non-standard http status code,
	// which defined by nginx.
	// https://httpstatus.in/499/
	StatusClientClosed = 499
)

Variables

View Source
var (
	// optional int32 code = 1109;
	E_Code = &file_errors_errors_proto_extTypes[1]
)

Extension fields to descriptorpb.EnumValueOptions.

View Source
var (
	// optional int32 default_code = 1108;
	E_DefaultCode = &file_errors_errors_proto_extTypes[0]
)

Extension fields to descriptorpb.EnumOptions.

View Source
var File_errors_errors_proto protoreflect.FileDescriptor

Functions

func As added in v0.2.0

func As(err error, target interface{}) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.

As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.

func Code added in v0.2.0

func Code(err error) int

Code returns the http code for a error. It supports wrapped errors.

func ContentSubtype added in v0.2.0

func ContentSubtype(contentType string) string

ContentSubtype returns the content-subtype for the given content-type. The given content-type must be a valid content-type that starts with but no content-subtype will be returned. according rfc7231. contentType is assumed to be lowercase already.

func ContentType added in v0.2.0

func ContentType(subtype string) string

ContentType returns the content-type with base prefix.

func Errorf added in v0.2.0

func Errorf(code, status int32, reason, format string, a ...interface{}) error

Errorf returns an error object for the code, message and error info.

func GRPCCodeFromStatus added in v0.2.0

func GRPCCodeFromStatus(code int32) codes.Code

GRPCCodeFromStatus converts a HTTP error code into the corresponding gRPC response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

func Is added in v0.2.0

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.

func Reason added in v0.2.0

func Reason(err error) string

Reason returns the reason for a particular error. It supports wrapped errors.

func Status added in v0.3.1

func Status(err error) int

func StatusFromGRPCCode added in v0.2.0

func StatusFromGRPCCode(code codes.Code) int32

StatusFromGRPCCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

func Unwrap added in v0.2.0

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

Types

type Error

type Error struct {
	Code     int32             `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Status   int32             `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
	Reason   string            `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"`
	Message  string            `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"`
	Metadata map[string]string `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

func FromError added in v0.2.0

func FromError(err error) *Error

FromError try to convert an error to *Error. It supports wrapped errors.

func New added in v0.2.0

func New(code, status int32, reason, message string) *Error

New returns an error object for the code, message.

func Newf added in v0.2.0

func Newf(code, status int32, reason, format string, a ...interface{}) *Error

Newf New(code fmt.Sprintf(format, a...))

func (*Error) Descriptor deprecated

func (*Error) Descriptor() ([]byte, []int)

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error added in v0.2.0

func (e *Error) Error() string

func (*Error) GRPCStatus added in v0.2.0

func (e *Error) GRPCStatus() *status.Status

GRPCStatus returns the Status represented by se.

func (*Error) GetCode

func (x *Error) GetCode() int32

func (*Error) GetMessage

func (x *Error) GetMessage() string

func (*Error) GetMetadata

func (x *Error) GetMetadata() map[string]string

func (*Error) GetReason

func (x *Error) GetReason() string

func (*Error) GetStatus added in v0.3.1

func (x *Error) GetStatus() int32

func (*Error) Is added in v0.2.0

func (e *Error) Is(err error) bool

Is matches each error in the chain with the target value.

func (*Error) ProtoMessage

func (*Error) ProtoMessage()

func (*Error) ProtoReflect

func (x *Error) ProtoReflect() protoreflect.Message

func (*Error) Reset

func (x *Error) Reset()

func (*Error) String

func (x *Error) String() string

func (*Error) WithMetadata added in v0.2.0

func (e *Error) WithMetadata(md map[string]string) *Error

WithMetadata with an MD formed by the mapping of key, value.

Jump to

Keyboard shortcuts

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