Documentation ¶
Index ¶
- Constants
- Variables
- func As(err error, target interface{}) bool
- func Code(err error) int
- func ContentSubtype(contentType string) string
- func ContentType(subtype string) string
- func Errorf(code, status int32, reason, format string, a ...interface{}) error
- func GRPCCodeFromStatus(code int32) codes.Code
- func Is(err, target error) bool
- func Reason(err error) string
- func Status(err error) int
- func StatusFromGRPCCode(code codes.Code) int32
- func Unwrap(err error) error
- type Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (e *Error) Error() string
- func (e *Error) GRPCStatus() *status.Status
- func (x *Error) GetCode() int32
- func (x *Error) GetMessage() string
- func (x *Error) GetMetadata() map[string]string
- func (x *Error) GetReason() string
- func (x *Error) GetStatus() int32
- func (e *Error) Is(err error) bool
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (x *Error) String() string
- func (e *Error) WithMetadata(md map[string]string) *Error
Constants ¶
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 )
const ( // StatusClientClosed is non-standard http status code, // which defined by nginx. // https://httpstatus.in/499/ StatusClientClosed = 499 )
Variables ¶
var (
// optional int32 code = 1109;
E_Code = &file_errors_errors_proto_extTypes[1]
)
Extension fields to descriptorpb.EnumValueOptions.
var (
// optional int32 default_code = 1108;
E_DefaultCode = &file_errors_errors_proto_extTypes[0]
)
Extension fields to descriptorpb.EnumOptions.
var File_errors_errors_proto protoreflect.FileDescriptor
Functions ¶
func As ¶ added in v0.2.0
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 ContentSubtype ¶ added in v0.2.0
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
ContentType returns the content-type with base prefix.
func GRPCCodeFromStatus ¶ added in v0.2.0
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
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
Reason returns the reason for a particular error. It supports wrapped errors.
func StatusFromGRPCCode ¶ added in v0.2.0
StatusFromGRPCCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
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
FromError try to convert an error to *Error. It supports wrapped errors.
func (*Error) Descriptor
deprecated
func (*Error) GRPCStatus ¶ added in v0.2.0
GRPCStatus returns the Status represented by se.
func (*Error) GetMessage ¶
func (*Error) GetMetadata ¶
func (*Error) ProtoMessage ¶
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶
func (x *Error) ProtoReflect() protoreflect.Message