Documentation
¶
Index ¶
- Constants
- Variables
- func Code(err error) int
- func Errorf(code int, reason, format string, a ...interface{}) error
- func FromGRPCCode(code codes.Code) int
- func Reason(err error) string
- func RegisterI18nManager(i18n I18nMessage)
- func ToGRPCCode(code int) codes.Code
- type Converter
- type Error
- type I18nMessage
- 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 ( // 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 )
View Source
const ( // ClientClosed is non-standard http status code, // which defined by nginx. // https://httpstatus.in/499/ ClientClosed = 499 )
Variables ¶
View Source
var (
// optional int32 default_http_code = 80000;
E_DefaultHttpCode = &file_errors_proto_extTypes[0]
)
Extension fields to descriptorpb.EnumOptions.
View Source
var (
// optional int32 http_code = 80000;
E_HttpCode = &file_errors_proto_extTypes[1]
)
Extension fields to descriptorpb.EnumValueOptions.
View Source
var File_errors_proto protoreflect.FileDescriptor
Functions ¶
func FromGRPCCode ¶
FromGRPCCode converts a gRPC error code into the corresponding HTTP response status.
func RegisterI18nManager ¶ added in v0.3.3
func RegisterI18nManager(i18n I18nMessage)
RegisterI18nManager Register the global i18n manager
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 Error ¶
type Error struct { Status // contains filtered or unexported fields }
Error is a status error.
func NewWithContext ¶ added in v0.3.3
NewWithContext Use context to create error objects and support i18n localization
func (*Error) GRPCStatus ¶
GRPCStatus returns the Status represented by se.
type I18nMessage ¶ added in v0.3.3
type I18nMessage interface { // Localize Localization of error causes based on context and data Localize(ctx context.Context, reason string, data any) string }
I18nMessage An interface to internationalize error messages is defined
type Status ¶
type Status struct { Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // The status code. Reason string `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"` // A unique identifier of the error Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // A human-readable description of the error Metadata map[string]string `` // A map of metadata for the error, e.g. the trace id /* 143-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.