ecode

package
v2.1.14 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

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_errors_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 ErrorV2 added in v2.1.7

type ErrorV2 struct {
	Status
	// 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, message string) *ErrorV2

NewV2 returns an error object for the code, message.

func NewV2WithReason added in v2.1.7

func NewV2WithReason(code int, reason string, message string) *ErrorV2

NewV2WithReason returns an error object for the code, message.

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, reason ...string) 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 message of the error.

func (*ErrorV2) Reason added in v2.1.7

func (e *ErrorV2) Reason() string

Reason returns the reason 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.

type Status added in v2.1.7

type Status 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 (*Status) Descriptor deprecated added in v2.1.7

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

Deprecated: Use Status.ProtoReflect.Descriptor instead.

func (*Status) GetCode added in v2.1.7

func (x *Status) GetCode() int32

func (*Status) GetMessage added in v2.1.7

func (x *Status) GetMessage() string

func (*Status) GetMetadata added in v2.1.7

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

func (*Status) GetReason added in v2.1.7

func (x *Status) GetReason() string

func (*Status) ProtoMessage added in v2.1.7

func (*Status) ProtoMessage()

func (*Status) ProtoReflect added in v2.1.7

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

func (*Status) Reset added in v2.1.7

func (x *Status) Reset()

func (*Status) String added in v2.1.7

func (x *Status) String() string

Jump to

Keyboard shortcuts

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