errors

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownReason = "UNKNOWN_REASON"
	UnknownCode   = 600

	InvalidParam   = "PARAM_INVALID"
	ParamValidCode = 601

	InvalidFormat     = "FORMAT_INVALID"
	FormatInvalidCode = 602

	Panic     = "SERVER_SLEEPY"
	PanicCode = 603

	SupportPackageIsVersion1 = true

	ClientClosed = 499
)

Variables

View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func Code

func Code(err error) int

func GRPCToHTTPCode added in v1.1.0

func GRPCToHTTPCode(code codes.Code) int

func HTTPToGRPCCode added in v1.1.0

func HTTPToGRPCCode(code int) codes.Code

func HasStack added in v1.1.1

func HasStack(err error) bool

func Message added in v1.1.0

func Message(err error) string

func Metadata added in v1.1.1

func Metadata(err error) map[string]string

func Reason

func Reason(err error) string

func Surplus added in v1.1.1

func Surplus(err error) interface{}

func Wrap added in v1.1.0

func Wrap(err error, text string) error

Types

type Error

type Error struct {
	Status

	Surplus interface{}
	// contains filtered or unexported fields
}

func BadRequest

func BadRequest(msg, reason string) *Error

func FormatInvalid

func FormatInvalid(msg, reason string) *Error

func FromError

func FromError(err error) *Error

func InternalServer

func InternalServer(msg, reason string) *Error

func New added in v1.1.0

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

func ParamInvalid added in v1.1.1

func ParamInvalid(msg, reason string) *Error

func ParseErr added in v1.1.0

func ParseErr(err error) *Error

func Unauthorized added in v1.1.2

func Unauthorized(msg, reason string) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format added in v1.1.0

func (e *Error) Format(s fmt.State, verb rune)

func (*Error) GRPCStatus

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

func (*Error) Is

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

func (*Error) Stack added in v1.1.0

func (e *Error) Stack() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithError

func (e *Error) WithError(cause error) *Error

func (*Error) WithMessage

func (e *Error) WithMessage(msg string) *Error

func (*Error) WithMetadata

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

func (*Error) WithReason added in v1.1.0

func (e *Error) WithReason(reason string) *Error

func (*Error) WithSurplus

func (e *Error) WithSurplus(surplus interface{}) *Error

type Stack added in v1.1.1

type Stack interface {
	Error() string
	Stack() string
}

type Status

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

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

Deprecated: Use Status.ProtoReflect.Descriptor instead.

func (*Status) GetCode

func (x *Status) GetCode() int32

func (*Status) GetMessage

func (x *Status) GetMessage() string

func (*Status) GetMetadata

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

func (*Status) GetReason

func (x *Status) GetReason() string

func (*Status) ProtoMessage

func (*Status) ProtoMessage()

func (*Status) ProtoReflect

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

func (*Status) Reset

func (x *Status) Reset()

func (*Status) String

func (x *Status) String() string

Jump to

Keyboard shortcuts

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