Documentation ¶
Index ¶
- Constants
- Variables
- func As(err error, target interface{}) bool
- func Code(err error) int
- func ErrorFmt(code int, reason, format string, a ...interface{}) error
- func Is(err, target error) bool
- func IsBadRequest(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsInternalServer(err error) bool
- func IsNotFound(err error) bool
- func IsServiceUnavailable(err error) bool
- func IsUnauthorized(err error) bool
- func Reason(err error) string
- func Unwrap(err error) error
- type Error
- func BadRequest(reason, message string) *Error
- func Conflict(reason, message string) *Error
- func Forbidden(reason, message string) *Error
- func FromError(err error) *Error
- func InternalServer(reason, message string) *Error
- func New(code int, reason, message string) *Error
- func NewFmt(code int, reason, format string, a ...interface{}) *Error
- func NotFound(reason, message string) *Error
- func ServiceUnavailable(reason, message string) *Error
- func Unauthorized(reason, message string) *Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (x *Error) Error() string
- func (x *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) Is(err error) bool
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (x *Error) StatusCode() int
- func (x *Error) String() string
- func (x *Error) WithMetadata(md map[string]string) *Error
Constants ¶
const ( // UnknownCode 是错误信息的未知代码. UnknownCode = 500 // UnknownReason 是错误信息的未知原因. UnknownReason = "" // SupportPackageIsVersion1 此常量不应被任何其他代码引用。 SupportPackageIsVersion1 = true )
Variables ¶
var (
// optional int32 code = 1109;
E_Code = &file_errors_proto_extTypes[1]
)
Extension fields to descriptorpb.EnumValueOptions.
var (
// optional int32 default_code = 1108;
E_DefaultCode = &file_errors_proto_extTypes[0]
)
Extension fields to descriptorpb.EnumOptions.
var File_errors_proto protoreflect.FileDescriptor
Functions ¶
func As ¶
As 在err链中找到与target匹配的第一个错误,如果匹配则将target设置为该错误值并返回true.
该链由err本身组成,其后是通过重复调用Unwrap获得的错误序列.
如果错误的具体值可分配给target指向的值,或者错误具有方法{As(interface{})bool}使得As(target)返回true,则错误与目标匹配。在后一种情况下,As方法负责设置目标. As 如果target不是实现错误的类型或任何接口类型的非nil指针将panic,如果err为nil,则返回false.
func Is ¶
Is 报告err链中的任何错误是否与target匹配.
该链由err本身组成,其后是通过重复调用Unwrap获得的错误序列. 如果错误等于target,或者它实现了{Is(error))bool}的方法使得Is(target)返回true,则认为该错误与该目标匹配 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 IsInternalServer ¶
IsInternalServer 确定err是否是指示InternalServer的错误,它支持包装错误.
func IsServiceUnavailable ¶
IsServiceUnavailable 确定err是否是指示ServiceUnavailable的错误,它支持包装错误.
func IsUnauthorized ¶
IsUnauthorized 确定err是否是表示Unauthorized的错误,它支持包装错误.
Types ¶
type Error ¶
type Error struct { Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` Reason string `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"` Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` Metadata map[string]string `` /* 157-byte string literal not displayed */ // contains filtered or unexported fields }
func InternalServer ¶
InternalServer 映射到500响应的新InternalServer错误.
func ServiceUnavailable ¶
ServiceUnavailable 映射到HTTP 503响应的新ServiceUnavailable错误.
func Unauthorized ¶
Unauthorized 映射到401响应的新的Unauthorized的错误.
func (*Error) Descriptor
deprecated
added in
v0.0.3
func (*Error) GetMessage ¶ added in v0.0.3
func (*Error) GetMetadata ¶ added in v0.0.3
func (*Error) ProtoMessage ¶ added in v0.0.3
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶ added in v0.0.3
func (x *Error) ProtoReflect() protoreflect.Message
func (*Error) StatusCode ¶ added in v0.0.3
StatusCode 返回一个WEB服务错误代码。