Documentation
¶
Index ¶
- func DebugInfo(stackEntries []string, detail string) *errdetails.DebugInfo
- func FromStatus(st *status.Status) *errx.Error
- func LocalizedMessage(locale, message string) *errdetails.LocalizedMessage
- func NewQuotaViolation(subject, description string) *errdetails.QuotaFailure_Violation
- func QuotaFailure(violations ...*errdetails.QuotaFailure_Violation) *errdetails.QuotaFailure
- func RegisterCode(c errx.Code, gc codes.Code)
- func RetryInfo(retryDelay time.Duration) *errdetails.RetryInfo
- func StreamServerInterceptor(opts ...InterceptorOption) grpc.StreamServerInterceptor
- func ToErrxCode(c codes.Code) errx.Code
- func ToGRPCCode(c errx.Code) codes.Code
- func ToStatus(err error) *status.Status
- func UnaryServerInterceptor(opts ...InterceptorOption) grpc.UnaryServerInterceptor
- type InterceptorOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugInfo ¶
func DebugInfo(stackEntries []string, detail string) *errdetails.DebugInfo
DebugInfo creates a DebugInfo detail.
func FromStatus ¶
FromStatus converts a *status.Status to an *errx.Error. Returns nil if the status code is OK. Any gRPC status details are restored via errx.WithDetails.
func LocalizedMessage ¶
func LocalizedMessage(locale, message string) *errdetails.LocalizedMessage
LocalizedMessage creates a LocalizedMessage detail.
func NewQuotaViolation ¶
func NewQuotaViolation(subject, description string) *errdetails.QuotaFailure_Violation
NewQuotaViolation creates a single QuotaFailure_Violation.
func QuotaFailure ¶
func QuotaFailure(violations ...*errdetails.QuotaFailure_Violation) *errdetails.QuotaFailure
QuotaFailure creates a QuotaFailure with the given violations.
func RegisterCode ¶
RegisterCode registers a custom mapping between an errx.Code and a gRPC codes.Code. Both forward (errx → gRPC) and reverse (gRPC → errx) mappings are registered. Must be called at program initialization (e.g. in init()), before serving requests.
func RetryInfo ¶
func RetryInfo(retryDelay time.Duration) *errdetails.RetryInfo
RetryInfo creates a RetryInfo detail with the given retry delay.
func StreamServerInterceptor ¶
func StreamServerInterceptor(opts ...InterceptorOption) grpc.StreamServerInterceptor
StreamServerInterceptor returns a gRPC stream server interceptor that converts returned errors to gRPC status errors using ToStatus. If the error implements errx.Localizable, a LocalizedMessage detail is automatically appended.
func ToErrxCode ¶
ToErrxCode maps a gRPC codes.Code to an errx.Code. codes.OK maps to the zero value ("").
func ToGRPCCode ¶
ToGRPCCode maps an errx.Code to a gRPC codes.Code. Unknown or user-defined codes map to codes.Unknown.
func ToStatus ¶
ToStatus converts an error to a *status.Status. If the error carries an errx.Code, it is mapped to a gRPC code. The error message is used as the status message. Any detail objects (proto.Message) attached via errx.WithDetails are included as gRPC status details. Non-proto.Message details are ignored.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(opts ...InterceptorOption) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a gRPC unary server interceptor that converts returned errors to gRPC status errors using ToStatus. If the error implements errx.Localizable, a LocalizedMessage detail is automatically appended.
Types ¶
type InterceptorOption ¶
type InterceptorOption func(*interceptorConfig)
InterceptorOption configures the gRPC server interceptors.
func WithDefaultLocale ¶ added in v0.0.3
func WithDefaultLocale(tag language.Tag) InterceptorOption
WithDefaultLocale sets a fallback locale used when the locale function returns an empty string (e.g. no accept-language metadata).
func WithLocaleFunc ¶
func WithLocaleFunc(f func(context.Context) string) InterceptorOption
WithLocaleFunc sets a custom function to extract locale from context. The default parses the "accept-language" gRPC metadata value and returns the highest-priority language tag as a BCP 47 string.