Documentation
¶
Overview ¶
Package errcode provides error code handling with gRPC compatibility.
Index ¶
- func CloneAndCheck(code *errorpb.ErrCode) *errorpb.ErrCode
- func ConvertErr2Status(errCode *errorpb.ErrCode) *status.Status
- func Err2GrpcCode(err error) codes.Code
- func GetErrCodes() []*errorpb.ErrCode
- func GrpcCodeToHTTP(code codes.Code) int
- func Http2GrpcCode(code int32) codes.Code
- func IsGrpcAcceptable(err error) bool
- func MustProtoToAny(p proto.Message) *anypb.Any
- func MustStructToAny(p map[string]any) *anypb.Any
- func MustTagsToAny(tags errors.Tags) []*anypb.Any
- func NewCodeErr(code *errorpb.ErrCode, details ...proto.Message) error
- func NewCodeErrWithMap(code *errorpb.ErrCode, details ...map[string]any) error
- func NewCodeErrWithMsg(code *errorpb.ErrCode, msg string, details ...proto.Message) error
- func ParseErrToPb(err error) proto.Message
- func ParseError(err error) *errorpb.ErrCode
- func RegisterErrCodes(code *errorpb.ErrCode) error
- func WrapCode(err error, code *errorpb.ErrCode) error
- type ErrCode
- func (t *ErrCode) As(err any) bool
- func (t *ErrCode) Error() string
- func (t *ErrCode) Format(f fmt.State, verb rune)
- func (t *ErrCode) ID() string
- func (t *ErrCode) Is(err error) bool
- func (t *ErrCode) MarshalJSON() ([]byte, error)
- func (t *ErrCode) Proto() proto.Message
- func (t *ErrCode) String() string
- func (t *ErrCode) Unwrap() error
- type ErrorProto
- type GRPCStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneAndCheck ¶
CloneAndCheck clones and validates an error code.
func ConvertErr2Status ¶
ConvertErr2Status converts an error code to a gRPC status. Internal conversion, so that when err=nil, OK information is included in monitoring data.
func Err2GrpcCode ¶
Err2GrpcCode converts a standard Go error into its canonical code. Note that this is only used to translate the error returned by the server applications.
func GetErrCodes ¶
func GrpcCodeToHTTP ¶
GrpcCodeToHTTP converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
func Http2GrpcCode ¶
Http2GrpcCode converts an HTTP status code to a gRPC code.
func IsGrpcAcceptable ¶
IsGrpcAcceptable checks if a gRPC error is acceptable for retry.
func NewCodeErrWithMap ¶
func NewCodeErrWithMsg ¶
func ParseErrToPb ¶
func ParseError ¶
ParseError tries to convert an error to *Error. It supports wrapped errors.
func RegisterErrCodes ¶
Types ¶
type ErrCode ¶
type ErrCode struct {
// contains filtered or unexported fields
}
ErrCode represents an error with code information.
func (*ErrCode) MarshalJSON ¶
type ErrorProto ¶
ErrorProto is an interface for errors that can be converted to protobuf messages.
type GRPCStatus ¶
GRPCStatus is an interface for errors that have gRPC status.