errors

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// UnknownCode 是错误信息的未知代码.
	UnknownCode = 500
	// UnknownReason 是错误信息的未知原因.
	UnknownReason = ""
	// SupportPackageIsVersion1 此常量不应被任何其他代码引用。
	SupportPackageIsVersion1 = true
)

Variables

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

Extension fields to descriptorpb.EnumValueOptions.

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

Extension fields to descriptorpb.EnumOptions.

View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func As

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

As 在err链中找到与target匹配的第一个错误,如果匹配则将target设置为该错误值并返回true.

该链由err本身组成,其后是通过重复调用Unwrap获得的错误序列.

如果错误的具体值可分配给target指向的值,或者错误具有方法{As(interface{})bool}使得As(target)返回true,则错误与目标匹配。在后一种情况下,As方法负责设置目标. As 如果target不是实现错误的类型或任何接口类型的非nil指针将panic,如果err为nil,则返回false.

func Code

func Code(err error) int

Code 返回特定错误的代码,它支持包装错误.

func ErrorFmt

func ErrorFmt(code int, reason, format string, a ...interface{}) error

ErrorFmt 返回代码,消息和错误信息的错误对象.

func Is

func Is(err, target error) bool

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 IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest 确定err是否是表示BadRequest的错误,它支持包装错误.

func IsConflict

func IsConflict(err error) bool

IsConflict 确定err是否是表示Conflict的错误,它支持包装错误.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden 确定err是否是表示Forbidden的错误,它支持包装错误.

func IsInternalServer

func IsInternalServer(err error) bool

IsInternalServer 确定err是否是指示InternalServer的错误,它支持包装错误.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound 确定err是否是表示NotFound的错误,它支持包装错误.

func IsServiceUnavailable

func IsServiceUnavailable(err error) bool

IsServiceUnavailable 确定err是否是指示ServiceUnavailable的错误,它支持包装错误.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized 确定err是否是表示Unauthorized的错误,它支持包装错误.

func Reason

func Reason(err error) string

Reason 返回特定错误的原因,它支持包装错误.

func Unwrap

func Unwrap(err error) error

Unwrap 如果err的类型包含返回错误的Unwrap方法,则返回对err调用Unwrap方法的结果.否则Unwrap返回nil.

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 BadRequest

func BadRequest(reason, message string) *Error

BadRequest 映射到400响应的新BadRequest错误.

func Conflict

func Conflict(reason, message string) *Error

Conflict 映射到409响应的新的Conflict错误.

func Forbidden

func Forbidden(reason, message string) *Error

Forbidden 映射到403响应的新的Forbidden错误.

func FromError

func FromError(err error) *Error

FromError 尝试将错误转换为*Error,它支持包装错误.

func InternalServer

func InternalServer(reason, message string) *Error

InternalServer 映射到500响应的新InternalServer错误.

func New

func New(code int, reason, message string) *Error

New 返回代码的错误对象,消息.

func NewFmt

func NewFmt(code int, reason, format string, a ...interface{}) *Error

NewFmt NewFmt(code reason fmt.Sprintf(format, a...))

func NotFound

func NotFound(reason, message string) *Error

NotFound 映射到404响应的新NotFound错误.

func ServiceUnavailable

func ServiceUnavailable(reason, message string) *Error

ServiceUnavailable 映射到HTTP 503响应的新ServiceUnavailable错误.

func Unauthorized

func Unauthorized(reason, message string) *Error

Unauthorized 映射到401响应的新的Unauthorized的错误.

func (*Error) Descriptor deprecated added in v0.0.3

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

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error

func (x *Error) Error() string

func (*Error) GRPCStatus

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

GRPCStatus 返回由se表示的Status.

func (*Error) GetCode added in v0.0.3

func (x *Error) GetCode() int32

func (*Error) GetMessage added in v0.0.3

func (x *Error) GetMessage() string

func (*Error) GetMetadata added in v0.0.3

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

func (*Error) GetReason added in v0.0.3

func (x *Error) GetReason() string

func (*Error) Is

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

Is 将链中的每个错误与目标值匹配.

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) Reset added in v0.0.3

func (x *Error) Reset()

func (*Error) StatusCode added in v0.0.3

func (x *Error) StatusCode() int

StatusCode 返回一个WEB服务错误代码。

func (*Error) String added in v0.0.3

func (x *Error) String() string

func (*Error) WithMetadata

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

WithMetadata 通过KV键值的映射形成的元数据.

Jump to

Keyboard shortcuts

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