errors

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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) codes.Code

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

func Domain

func Domain(err error) string

Domain 返回特定错误的服务,它支持包装错误.

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 {
	Domain   string            `json:"domain"`
	Reason   string            `json:"reason"`
	Metadata map[string]string `json:"metadata"`
	// contains filtered or unexported fields
}

Error 包含来自服务器的错误响应. 有关更多详细信息,请参见https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto.

func BadRequest

func BadRequest(service, reason, message string) *Error

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

func Conflict

func Conflict(service, reason, message string) *Error

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

func ErrorFmt

func ErrorFmt(code codes.Code, domain, reason, format string, a ...interface{}) *Error

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

func Forbidden

func Forbidden(service, reason, message string) *Error

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

func FromError

func FromError(err error) *Error

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

func InternalServer

func InternalServer(service, reason, message string) *Error

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

func New

func New(code codes.Code, domain, reason, message string) *Error

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

func NewFmt

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

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

func NotFound

func NotFound(service, reason, message string) *Error

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

func ServiceUnavailable

func ServiceUnavailable(service, reason, message string) *Error

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

func Unauthorized

func Unauthorized(service, reason, message string) *Error

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

func (*Error) Error

func (e *Error) Error() string

func (*Error) GRPCStatus

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

GRPCStatus 返回由se表示的Status.

func (*Error) Is

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

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

func (*Error) WithMetadata

func (e *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