ecode

package
v2.1.41 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// UnknownCode is unknown code for error info.
	UnknownCode     = http.StatusInternalServerError
	SystemErrorCode = -1
	// UnknownReason is unknown reason for error info.
	UnknownReason = ""
	// ClientClosed is non-standard http status code,
	// which defined by nginx.
	// https://httpstatus.in/499/
	ClientClosed = 499
)

Variables

View Source
var (
	// base error
	Success     = NewV2(1, "success")
	SystemError = NewV2(SystemErrorCode, "system error")
)
View Source
var DefaultConverter = statusConverter{}

DefaultConverter default converter.

View Source
var File_api_ecode_errors_v2_proto protoreflect.FileDescriptor

Functions

func New

func New(code int, err error) error

New 注册Error异常

func Transform added in v2.0.2

func Transform(err error) int

Transform 通过error获取对应的code码

Types

type ErrorStatus added in v2.1.20

type ErrorStatus struct {
	Code     int64             `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Msg      string            `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
	Metadata map[string]string `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*ErrorStatus) Descriptor deprecated added in v2.1.20

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

Deprecated: Use ErrorStatus.ProtoReflect.Descriptor instead.

func (*ErrorStatus) GetCode added in v2.1.20

func (x *ErrorStatus) GetCode() int64

func (*ErrorStatus) GetMetadata added in v2.1.20

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

func (*ErrorStatus) GetMsg added in v2.1.20

func (x *ErrorStatus) GetMsg() string

func (*ErrorStatus) ProtoMessage added in v2.1.20

func (*ErrorStatus) ProtoMessage()

func (*ErrorStatus) ProtoReflect added in v2.1.20

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

func (*ErrorStatus) Reset added in v2.1.20

func (x *ErrorStatus) Reset()

func (*ErrorStatus) String added in v2.1.20

func (x *ErrorStatus) String() string

type ErrorV2 added in v2.1.7

type ErrorV2 struct {
	ErrorStatus
	// contains filtered or unexported fields
}

ErrorV2 struct

func AnalyseErrorV2 added in v2.1.7

func AnalyseErrorV2(err error) *ErrorV2

analyse error info

func DeepClone added in v2.1.7

func DeepClone(err *ErrorV2) *ErrorV2

DeepClone deep clone error to a new error.

func FromError added in v2.1.7

func FromError(err error) *ErrorV2

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

func NewV2 added in v2.1.7

func NewV2(code int, msg string) *ErrorV2

NewV2 returns an error object for the code, msg.

func (*ErrorV2) Code added in v2.1.7

func (e *ErrorV2) Code() int

Code returns the code of the error.

func (*ErrorV2) Equal added in v2.1.7

func (e *ErrorV2) Equal(code int) bool

Equal matches error from code and reason.

func (*ErrorV2) Error added in v2.1.7

func (e *ErrorV2) Error() string

func (*ErrorV2) GRPCStatus added in v2.1.7

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

GRPCStatus returns the Status represented by error.

func (*ErrorV2) Is added in v2.1.7

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

Is matches each error in the chain with the target value.

func (*ErrorV2) Message added in v2.1.7

func (e *ErrorV2) Message() string

Message returns the msg of the error.

func (*ErrorV2) Unwrap added in v2.1.7

func (e *ErrorV2) Unwrap() error

Unwrap provides compatibility for Go 1.13 error chains.

func (*ErrorV2) WithCause added in v2.1.7

func (e *ErrorV2) WithCause(cause error) *ErrorV2

WithCause with the underlying cause of the error.

func (*ErrorV2) WithMetadata added in v2.1.7

func (e *ErrorV2) WithMetadata(md map[string]string) *ErrorV2

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

Jump to

Keyboard shortcuts

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