Documentation
¶
Index ¶
- func DecodeErrorFromStatus(ctx context.Context, err error) error
- func MapToGRPC(err error, defaultCode codes.Code) codes.Code
- func PrepareAndLogGRPCStatus(err error, logger logging.Logger, span tracing.Span, defaultCode codes.Code, ...) error
- func RegisterGRPCErrorMapper(m GRPCErrorMapper)
- func StreamErrorEncodingInterceptor() grpc.StreamServerInterceptor
- func UnaryErrorEncodingInterceptor() grpc.UnaryServerInterceptor
- type GRPCErrorMapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeErrorFromStatus ¶
DecodeErrorFromStatus extracts the EncodedError from gRPC status details (if present) and decodes it so errors.Is() works across the wire. Returns the decoded error, or the original status error if no encoded detail is found.
func MapToGRPC ¶
MapToGRPC returns the appropriate gRPC code for known sentinel errors. It tries PlatformMapper first, then each registered domain mapper. Use std errors.Is for matching. Returns defaultCode if no match.
func PrepareAndLogGRPCStatus ¶
func PrepareAndLogGRPCStatus(err error, logger logging.Logger, span tracing.Span, defaultCode codes.Code, descriptionFmt string, descriptionArgs ...any) error
PrepareAndLogGRPCStatus derives the gRPC code via MapToGRPC, then logs, traces, and returns a status error. Use defaultCode as the fallback for unknown errors.
func RegisterGRPCErrorMapper ¶
func RegisterGRPCErrorMapper(m GRPCErrorMapper)
RegisterGRPCErrorMapper registers a domain-specific error mapper. Domains call this from init() to contribute their error mappings.
func StreamErrorEncodingInterceptor ¶
func StreamErrorEncodingInterceptor() grpc.StreamServerInterceptor
StreamErrorEncodingInterceptor returns a stream interceptor that encodes handler errors into gRPC status details for wire transmission.
func UnaryErrorEncodingInterceptor ¶
func UnaryErrorEncodingInterceptor() grpc.UnaryServerInterceptor
UnaryErrorEncodingInterceptor returns a unary interceptor that encodes handler errors into gRPC status details for wire transmission. Handlers should return errors (optionally wrapped); the interceptor will derive the gRPC code via MapToGRPC and attach the encoded error to details.
Types ¶
type GRPCErrorMapper ¶
GRPCErrorMapper maps domain errors to gRPC codes. ok=false means no match.
var PlatformMapper GRPCErrorMapper = platformMapper{}
PlatformMapper maps platform-level errors to gRPC codes. It does not depend on any domain.