Documentation ¶
Index ¶
- Constants
- Variables
- func As(err error, target interface{}) bool
- func Code(err error) int
- func Errorf(code int, reason, format string, a ...interface{}) error
- func Is(err, target error) bool
- func IsBadRequest(err error) bool
- func IsClientClosed(err error) bool
- func IsConflict(err error) bool
- func IsDB(e error) bool
- func IsExisted(e error) bool
- func IsForbidden(err error) bool
- func IsGatewayTimeout(err error) bool
- func IsInternalServer(err error) bool
- func IsNotFound(err error) bool
- func IsNotImplemented(err error) bool
- func IsParamWrong(e error) bool
- func IsRPC(e error) bool
- func IsRedis(e error) bool
- func IsServiceUnavailable(err error) bool
- func IsSessionExpired(e error) bool
- func IsThirdParty(e error) bool
- func IsTooManyRequests(err error) bool
- func IsUnauthorized(err error) bool
- func IsUnknown(e error) bool
- func Reason(err error) string
- func Unwrap(err error) error
- type Error
- func BadRequest(reason, message string) *Error
- func ClientClosed(reason, message string) *Error
- func Conflict(reason, message string) *Error
- func DB(e ...error) *Error
- func Existed(e ...error) *Error
- func Forbidden(reason, message string) *Error
- func FromError(err error) *Error
- func GatewayTimeout(reason, message string) *Error
- func InternalServer(reason, message string) *Error
- func New(code int, reason, message string) *Error
- func Newf(code int, reason, format string, a ...interface{}) *Error
- func NotFound(reason, message string) *Error
- func NotImplemented(reason, message string) *Error
- func ParamWrong(e ...error) *Error
- func RPC(e ...error) *Error
- func Redis(e ...error) *Error
- func ServiceUnavailable(reason, message string) *Error
- func SessionExpired(e ...error) *Error
- func ThirdParty(e ...error) *Error
- func TooManyRequests(reason, message string) *Error
- func Unauthorized(reason, message string) *Error
- func Unknown(e ...error) *Error
- func (x *Error) CopyWithCauseError(e error) *Error
- func (x *Error) CopyWithMessage(msg string) *Error
- func (x *Error) CopyWithMetadata(md map[string]string) *Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (x *Error) Error() string
- func (x *Error) GRPCStatus() *status.Status
- func (x *Error) GetCode() int32
- func (x *Error) GetMessage() string
- func (x *Error) GetMetadata() map[string]string
- func (x *Error) GetReason() string
- func (x *Error) Is(err error) bool
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (x *Error) String() string
Constants ¶
const ( // UnknownCode is unknown code for error info. UnknownCode = 500 // UnknownReason is unknown reason for error info. UnknownReason = "" // SupportPackageIsVersion1 this constant should not be referenced by any other code. SupportPackageIsVersion1 = true )
const ( DefaultReasonDB = "DB_ERROR" DefaultReasonRedis = "REDIS_ERROR" DefaultReasonRPC = "RPC_ERROR" DefaultReasonUnknown = "INTERNAL_ERROR" DefaultReasonThirdParty = "THIRD_PARTY_ERROR" DefaultReasonParamWrong = "INVALID_PARAM" DefaultReasonSessionExpired = "SESSION_EXPIRED" DefaultReasonExisted = "ALREADY_EXISTED" DefaultMessageDB = "db error" DefaultMessageRedis = "redis error" DefaultMessageRPC = "internal rpc service error" DefaultMessageUnknown = "internal error" DefaultMessageThirdParty = "call third_party api failed" DefaultMessageParamWrong = "invalid param" DefaultMessageSessionExpired = "session expired" DefaultMessageExisted = "resource is already existed" )
const ( DefaultReasonBadRequest = "INVALID_PARAM" DefaultReasonForbidden = "FORBIDDEN" DefaultReasonNotFound = "NOT_FOUND" DefaultReasonConflict = "CONFLICT" DefaultReasonTooManyRequests = "TOO_MANY_REQUESTS" DefaultReasonInternalServer = "INTERNAL_SERVER" DefaultReasonNotImplemented = "NOT_IMPLEMENTED" DefaultReasonGatewayTimeout = "GATEWAY_TIMEOUT" DefaultReasonClientClosed = "CLIENT_CLOSED" DefaultMessageBadRequest = "invalid param" DefaultMessageForbidden = "forbidden" DefaultMessageNotFound = "not found" DefaultMessageConflict = "conflict" DefaultMessageTooManyRequests = "too many requests" DefaultMessageInternalServer = "internal server" DefaultMessageNotImplemented = "not implemented" DefaultMessageGateWayTimeout = "gateway timeout" DefaultMessageClientClosed = "client closed" )
Variables ¶
var ( // optional int32 code = 100001; E_Code = &file_errors_proto_extTypes[1] // optional string message = 100002; E_Message = &file_errors_proto_extTypes[2] )
Extension fields to descriptorpb.EnumValueOptions.
var (
// optional int32 default_code = 100001;
E_DefaultCode = &file_errors_proto_extTypes[0]
)
Extension fields to descriptorpb.EnumOptions.
var File_errors_proto protoreflect.FileDescriptor
Functions ¶
func As ¶
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.
As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.
func Is ¶
Is reports whether any error in err's chain matches target.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
func IsBadRequest ¶
IsBadRequest determines if err is an error which indicates a BadRequest error. It supports wrapped errors.
func IsClientClosed ¶
IsClientClosed determines if err is an error which indicates a ClientClosed error. It supports wrapped errors.
func IsConflict ¶
IsConflict determines if err is an error which indicates a Conflict error. It supports wrapped errors.
func IsForbidden ¶
IsForbidden determines if err is an error which indicates a Forbidden error. It supports wrapped errors.
func IsGatewayTimeout ¶
IsGatewayTimeout determines if err is an error which indicates a GatewayTimeout error. It supports wrapped errors.
func IsInternalServer ¶
IsInternalServer determines if err is an error which indicates an Internal error. It supports wrapped errors.
func IsNotFound ¶
IsNotFound determines if err is an error which indicates an NotFound error. It supports wrapped errors.
func IsNotImplemented ¶
IsNotImplemented determines if err is an error which indicates an NotImplemented error. It supports wrapped errors.
func IsParamWrong ¶
func IsServiceUnavailable ¶
IsServiceUnavailable determines if err is an error which indicates an Unavailable error. It supports wrapped errors.
func IsSessionExpired ¶
func IsThirdParty ¶
func IsTooManyRequests ¶
IsTooManyRequests determines if err is an error which indicates a TooManyRequests error. It supports wrapped errors.
func IsUnauthorized ¶
IsUnauthorized determines if err is an error which indicates an Unauthorized error. It supports wrapped errors.
Types ¶
type Error ¶
type Error 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 BadRequest ¶
BadRequest new BadRequest error that is mapped to a 400 response.
func ClientClosed ¶
ClientClosed new ClientClosed error that is mapped to an HTTP 499 response.
func GatewayTimeout ¶
GatewayTimeout new GatewayTimeout error that is mapped to an HTTP 504 response.
func InternalServer ¶
InternalServer new InternalServer error that is mapped to a 500 response.
func NotImplemented ¶
NotImplemented new NotImplemented error that is mapped to a 500 response.
func ParamWrong ¶
func ServiceUnavailable ¶
ServiceUnavailable new ServiceUnavailable error that is mapped to an HTTP 503 response.
func SessionExpired ¶
func ThirdParty ¶
func TooManyRequests ¶
TooManyRequests new TooManyRequests error that is mapped to an HTTP 429 response.
func Unauthorized ¶
Unauthorized new Unauthorized error that is mapped to a 401 response.
func (*Error) CopyWithCauseError ¶
CopyWithCauseError copies the error instance and returns a new one with given error.
func (*Error) CopyWithMessage ¶
CopyWithMessage copies the error instance and returns a new one with given message.
func (*Error) CopyWithMetadata ¶
CopyWithMetadata copies the error instance and returns a new one with an MD formed by the mapping of key, value.
func (*Error) Descriptor
deprecated
func (*Error) GRPCStatus ¶
GRPCStatus returns the Status represented by se.
func (*Error) GetMessage ¶
func (*Error) GetMetadata ¶
func (*Error) ProtoMessage ¶
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶
func (x *Error) ProtoReflect() protoreflect.Message