errors

package
v0.0.0-...-4f74120 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnknownCode is unknown code for error info.
	UnknownCode = 500
	// UnknownReason is unknown reason for error info.
	UnknownReason = ""
)

Variables

View Source
var ErrDetails = errors.New("no error details for status with code OK")
View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func As

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

func Code

func Code(err error) int

Code 返回err指定的错误码

func Is

func Is(err, target error) bool

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest determines if err is an error which indicates a BadRequest error. It supports wrapped errors.

func IsClientClosed

func IsClientClosed(err error) bool

IsClientClosed determines if err is an error which indicates a IsClientClosed error. It supports wrapped errors.

func IsConflict

func IsConflict(err error) bool

IsConflict determines if err is an error which indicates a Conflict error. It supports wrapped errors.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden determines if err is an error which indicates a Forbidden error. It supports wrapped errors.

func IsGatewayTimeout

func IsGatewayTimeout(err error) bool

IsGatewayTimeout determines if err is an error which indicates a GatewayTimeout error. It supports wrapped errors.

func IsInternalServer

func IsInternalServer(err error) bool

IsInternalServer determines if err is an error which indicates an Internal error. It supports wrapped errors.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound determines if err is an error which indicates an NotFound error. It supports wrapped errors.

func IsServiceUnavailable

func IsServiceUnavailable(err error) bool

IsServiceUnavailable determines if err is an error which indicates a Unavailable error. It supports wrapped errors.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized determines if err is an error which indicates a Unauthorized error. It supports wrapped errors.

func Reason

func Reason(err error) string

Reason 返回err的reason

func Unwrap

func Unwrap(err error) error

Types

type Error

type Error struct {

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

func BadRequest

func BadRequest(reason, message string) *Error

BadRequest new BadRequest error that is mapped to a 400 response.

func ClientClosed

func ClientClosed(reason, message string) *Error

ClientClosed new ClientClosed error that is mapped to a HTTP 499 response.

func Conflict

func Conflict(reason, message string) *Error

Conflict new Conflict error that is mapped to a 409 response.

func Errorf

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

func Forbidden

func Forbidden(reason, message string) *Error

Forbidden new Forbidden error that is mapped to a 403 response.

func FromError

func FromError(err error) *Error

func GatewayTimeout

func GatewayTimeout(reason, message string) *Error

GatewayTimeout new GatewayTimeout error that is mapped to a HTTP 504 response.

func InternalServer

func InternalServer(reason, message string) *Error

InternalServer new InternalServer error that is mapped to a 500 response.

func New

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

New 实例化 Error 对象

func NotFound

func NotFound(reason, message string) *Error

NotFound new NotFound error that is mapped to a 404 response.

func ServiceUnavailable

func ServiceUnavailable(reason, message string) *Error

ServiceUnavailable new ServiceUnavailable error that is mapped to a HTTP 503 response.

func Unauthorized

func Unauthorized(reason, message string) *Error

Unauthorized new Unauthorized error that is mapped to a 401 response.

func (*Error) AddMetadata

func (x *Error) AddMetadata(mp map[string]string) *Error

AddMetadata 增加metadata

func (*Error) Descriptor deprecated

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

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error

func (x *Error) Error() string

Error 实现Error接口

func (*Error) GRPCStatus

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

GRPCStatus 返回grpc status

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) Is

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

Is 跟 target Error 比较 判断是否相等

func (*Error) ProtoMessage

func (*Error) ProtoMessage()

func (*Error) ProtoReflect

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

func (*Error) Reset

func (x *Error) Reset()

func (*Error) StatusCode

func (x *Error) StatusCode() int

StatusCode HTTP code

func (*Error) String

func (x *Error) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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