errors

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

	Panic       = "SERVER_UNAVAILABLE"
	ParamError  = "PARAM_ERROR"
	FormatError = "FORMAT_ERROR"
	TokenError  = "TOKEN_ERROR"

	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 Is added in v1.2.2

func Is(err, target error) bool

func IsBadRequest added in v1.3.6

func IsBadRequest(err error) bool

func IsForbidden added in v1.3.6

func IsForbidden(err error) bool

func IsInternalServer added in v1.3.6

func IsInternalServer(err error) bool

func IsNotFound added in v1.3.6

func IsNotFound(err error) bool

func IsServerUnavailable added in v1.3.6

func IsServerUnavailable(err error) bool

func IsUnauthorized added in v1.3.6

func IsUnauthorized(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

BadRequest param / format error

func Forbidden added in v1.3.6

func Forbidden(msg, reason string) *Error

Forbidden token has no rights to access

func FromError

func FromError(err error) *Error

func InternalServer

func InternalServer(msg, reason string) *Error

InternalServer network / database error

func New added in v1.1.0

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

func NotFound added in v1.3.6

func NotFound(msg, reason string) *Error

func ServerUnavailable added in v1.3.6

func ServerUnavailable(msg, reason string) *Error

ServerUnavailable panic

func Unauthorized added in v1.1.2

func Unauthorized(msg, reason string) *Error

Unauthorized token invalid / expired

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