Documentation ¶
Index ¶
- Constants
- Variables
- func Code(err error) int
- func GRPCToHTTPCode(code codes.Code) int
- func HTTPToGRPCCode(code int) codes.Code
- func HasStack(err error) bool
- func Is(err, target error) bool
- func IsBadRequest(err error) bool
- func IsForbidden(err error) bool
- func IsInternalServer(err error) bool
- func IsNotFound(err error) bool
- func IsServerUnavailable(err error) bool
- func IsUnauthorized(err error) bool
- func Message(err error) string
- func Metadata(err error) map[string]string
- func Reason(err error) string
- func Surplus(err error) interface{}
- func Wrap(err error, text string) error
- type Error
- func BadRequest(msg, reason string) *Error
- func Forbidden(msg, reason string) *Error
- func FromError(err error) *Error
- func InternalServer(msg, reason string) *Error
- func New(code int, msg, reason string) *Error
- func NotFound(msg, reason string) *Error
- func ServerUnavailable(msg, reason string) *Error
- func Unauthorized(msg, reason string) *Error
- func (e *Error) Error() string
- func (e *Error) Format(s fmt.State, verb rune)
- func (e *Error) GRPCStatus() *status.Status
- func (e *Error) Is(err error) bool
- func (e *Error) Stack() string
- func (e *Error) Unwrap() error
- func (e *Error) WithError(cause error) *Error
- func (e *Error) WithMessage(msg string) *Error
- func (e *Error) WithMetadata(md map[string]string) *Error
- func (e *Error) WithReason(reason string) *Error
- func (e *Error) WithSurplus(surplus interface{}) *Error
- type Stack
- type Status
- func (*Status) Descriptor() ([]byte, []int)deprecated
- func (x *Status) GetCode() int32
- func (x *Status) GetMessage() string
- func (x *Status) GetMetadata() map[string]string
- func (x *Status) GetReason() string
- func (*Status) ProtoMessage()
- func (x *Status) ProtoReflect() protoreflect.Message
- func (x *Status) Reset()
- func (x *Status) String() string
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 GRPCToHTTPCode ¶ added in v1.1.0
func HTTPToGRPCCode ¶ added in v1.1.0
func IsBadRequest ¶ added in v1.3.6
func IsForbidden ¶ added in v1.3.6
func IsInternalServer ¶ added in v1.3.6
func IsNotFound ¶ added in v1.3.6
func IsServerUnavailable ¶ added in v1.3.6
func IsUnauthorized ¶ added in v1.3.6
Types ¶
type Error ¶
type Error struct { Status Surplus interface{} // contains filtered or unexported fields }
func InternalServer ¶
InternalServer network / database error
func ServerUnavailable ¶ added in v1.3.6
ServerUnavailable panic
func Unauthorized ¶ added in v1.1.2
Unauthorized token invalid / expired
func (*Error) GRPCStatus ¶
func (*Error) WithMessage ¶
func (*Error) WithReason ¶ added in v1.1.0
func (*Error) WithSurplus ¶
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) GetMessage ¶
func (*Status) GetMetadata ¶
func (*Status) ProtoMessage ¶
func (*Status) ProtoMessage()
func (*Status) ProtoReflect ¶
func (x *Status) ProtoReflect() protoreflect.Message
Click to show internal directories.
Click to hide internal directories.