Documentation ¶
Overview ¶
nolint:gomnd
Index ¶
- Constants
- Variables
- func ErrCode(err error) int32
- func ErrorIs(err error, errCode int32) bool
- func Errorf(statusCode int32, errCode int32, format string, a ...interface{}) error
- func FromGRPCCode(code codes.Code) int
- func IsBadRequest(err error) bool
- func IsClientClosed(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsGatewayTimeout(err error) bool
- func IsInternalServer(err error) bool
- func IsNotFound(err error) bool
- func IsServiceUnavailable(err error) bool
- func IsUnauthorized(err error) bool
- func RegisterError(codeMap map[int32]*ErrCodeDetail)
- func SetLang(l string)
- func StatusCode(err error) int
- func ToGRPCCode(code int) codes.Code
- type Converter
- type ErrCodeDetail
- type Error
- func BadRequest(message string) *Error
- func ClientClosed(message string) *Error
- func Clone(err *Error) *Error
- func Conflict(message string) *Error
- func CreateError(statusCode int32, errCode int32, message string) *Error
- func CreateErrorf(statusCode int32, errCode int32, format string, a ...interface{}) *Error
- func Forbidden(message string) *Error
- func FromError(err error) *Error
- func GatewayTimeout(message string) *Error
- func InternalServer(message string) *Error
- func New(errCode int32) *Error
- func NewWithMsg(errCode int32, msg string) *Error
- func NewWithStatus(statusCode int32, errCode int32) *Error
- func NotFound(message string) *Error
- func ServiceUnavailable(message string) *Error
- func Unauthorized(message string) *Error
- func (e *Error) Error() string
- func (e *Error) GRPCStatus() *status.Status
- func (e *Error) GetErrorCode() int32
- func (e *Error) GetStatusCode() int32
- func (e *Error) Is(err error) bool
- func (e *Error) IsErrCode(errCode int32) bool
- func (e *Error) JSONBytes() []byte
- func (e *Error) Unwrap() error
- func (e *Error) WithCause(cause error) *Error
- func (e *Error) WithMetadata(md map[string]string) *Error
- type ErrorInfo
- func (*ErrorInfo) Descriptor() ([]byte, []int)deprecated
- func (x *ErrorInfo) GetErrorCode() int32
- func (x *ErrorInfo) GetMessage() string
- func (x *ErrorInfo) GetMetadata() map[string]string
- func (x *ErrorInfo) GetStatusCode() int32
- func (*ErrorInfo) ProtoMessage()
- func (x *ErrorInfo) ProtoReflect() protoreflect.Message
- func (x *ErrorInfo) Reset()
- func (x *ErrorInfo) String() string
Constants ¶
const ( DefaultStatusCode = 400 UnknownStatusCode = 500 )
const ( ErrCodeUnknown int32 = -1 ErrCodeInvalidReqSys int32 = 40000 ErrCodeInvalidParamSys int32 = 40001 ErrCodeInvalidHeaderSys int32 = 40002 ErrCodeInvalidBodySys int32 = 40003 ErrCodeRecordNotFoundSys int32 = 40004 )
const ( // StatusClientClosed is non-standard http status code, // which defined by nginx. // https://httpstatus.in/499/ StatusClientClosed = 499 )
Variables ¶
var File_errorx_proto protoreflect.FileDescriptor
Functions ¶
func FromGRPCCode ¶
FromGRPCCode converts a gRPC error code into the corresponding HTTP response status.
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 IsClientClosed 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 IsServiceUnavailable ¶
IsServiceUnavailable determines if err is an error which indicates an Unavailable error. It supports wrapped errors.
func IsUnauthorized ¶
IsUnauthorized determines if err is an error which indicates an Unauthorized error. It supports wrapped errors.
func RegisterError ¶
func RegisterError(codeMap map[int32]*ErrCodeDetail)
func StatusCode ¶
StatusCode returns the http code for an error. It supports wrapped errorx.
func ToGRPCCode ¶
ToGRPCCode converts an HTTP error code into the corresponding gRPC response status.
Types ¶
type Converter ¶
type Converter interface { // ToGRPCCode converts an HTTP error code into the corresponding gRPC response status. ToGRPCCode(code int) codes.Code // FromGRPCCode converts a gRPC error code into the corresponding HTTP response status. FromGRPCCode(code codes.Code) int }
Converter is a status converter.
var DefaultConverter Converter = statusConverter{}
DefaultConverter default converter.
type ErrCodeDetail ¶
type Error ¶
type Error struct { ErrorInfo // contains filtered or unexported fields }
Error is a status error.
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 CreateError ¶
CreateError returns an error object for the status code, error code, message.
func CreateErrorf ¶
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 NewWithMsg ¶
NewWithMsg new error from errcode and message
func NewWithStatus ¶
NewWithStatus new error from errcode and message
func ServiceUnavailable ¶
ServiceUnavailable new ServiceUnavailable error that is mapped to an HTTP 503 response.
func Unauthorized ¶
Unauthorized new Unauthorized error that is mapped to a 401 response.
func (*Error) GRPCStatus ¶
func (*Error) GetErrorCode ¶
func (*Error) GetStatusCode ¶
type ErrorInfo ¶
type ErrorInfo struct { StatusCode int32 `protobuf:"varint,1,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` ErrorCode int32 `protobuf:"varint,2,opt,name=error_code,json=errorCode,proto3" json:"error_code,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 (*ErrorInfo) Descriptor
deprecated
func (*ErrorInfo) GetErrorCode ¶
func (*ErrorInfo) GetMessage ¶
func (*ErrorInfo) GetMetadata ¶
func (*ErrorInfo) GetStatusCode ¶
func (*ErrorInfo) ProtoMessage ¶
func (*ErrorInfo) ProtoMessage()
func (*ErrorInfo) ProtoReflect ¶
func (x *ErrorInfo) ProtoReflect() protoreflect.Message