eerrors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnknownReason is unknown reason for error info.
	UnknownReason = ""
	// SupportPackageIsVersion1 this constant should not be referenced by any other code.
	SupportPackageIsVersion1 = true
)

Variables

View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func Convert

func Convert(err error) *status.Status

Convert 内部转换,为了让err=nil的时候,监控数据里有OK信息

func GrpcToHTTPStatusCode

func GrpcToHTTPStatusCode(statusCode codes.Code) int

GrpcToHTTPStatusCode gRPC转HTTP Code example: spbStatus := status.FromContextError(err) httpStatusCode := ecode.GrpcToHTTPStatusCode(spbStatus.Code())

func IsCanceled

func IsCanceled(err *GoError) bool

IsCanceled determines if err is an error which indicates a Canceled error.

func IsDeadlineExceeded

func IsDeadlineExceeded(err *GoError) bool

IsDeadlineExceeded determines if err is an error which indicates a DeadlineExceeded error.

func IsNotFound

func IsNotFound(err *GoError) bool

IsNotFound determines if err is an error which indicates a NotFound error.

func Register

func Register(goError *GoError)

Register registers error instance.

Types

type Error

type Error interface {
	error
	WithMetadata(map[string]string) Error
	WithMd(map[string]string) Error
	WithMessage(string) Error
	WithMsg(string) Error
}

Error defines an grpc error that can be transformed between micro-service caller and micro-service callee.

type GoError

type GoError 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 Canceled

func Canceled(reason, message string) *GoError

Canceled new Canceled error that is mapped to context.Canceled.

func DeadlineExceeded

func DeadlineExceeded(reason, message string) *GoError

DeadlineExceeded new DeadlineExceeded error that is mapped to context.DeadlineExceeded.

func FromError

func FromError(err error) *GoError

FromError try to convert an error to *Error. It supports wrapped errors.

func New

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

New returns an error object for the code, message.

func NotFound

func NotFound(reason, message string) *GoError

NotFound new NotFound error that is mapped to context.NotFound.

func (*GoError) Descriptor deprecated

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

Deprecated: Use GoError.ProtoReflect.Descriptor instead.

func (*GoError) Error

func (x *GoError) Error() string

Error returns error detail message.

func (*GoError) GRPCStatus

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

GRPCStatus returns the Status represented by se.

func (*GoError) GetCode

func (x *GoError) GetCode() int32

func (*GoError) GetMessage

func (x *GoError) GetMessage() string

func (*GoError) GetMetadata

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

func (*GoError) GetReason

func (x *GoError) GetReason() string

func (*GoError) Is

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

Is will be called in errors.Is method to check error type.

func (*GoError) ProtoMessage

func (*GoError) ProtoMessage()

func (*GoError) ProtoReflect

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

func (*GoError) Reset

func (x *GoError) Reset()

func (*GoError) String

func (x *GoError) String() string

func (*GoError) ToHTTPStatusCode

func (x *GoError) ToHTTPStatusCode() int

ToHTTPStatusCode Get equivalent HTTP status code from x.Code

func (*GoError) WithMd

func (x *GoError) WithMd(md map[string]string) Error

WithMd with an MD formed by the mapping of key, value.

func (*GoError) WithMessage

func (x *GoError) WithMessage(msg string) Error

WithMessage set message to current GoError Deprecated: Will be removed in future versions, use WithMsg instead.

func (*GoError) WithMetadata

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

WithMetadata with an MD formed by the mapping of key, value. Deprecated: Will be removed in future versions, use WithMd instead.

func (*GoError) WithMsg

func (x *GoError) WithMsg(msg string) Error

WithMsg set message to current GoError

Jump to

Keyboard shortcuts

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