From b25816db53e4480d3cf9405a55744c92a1bdb620 Mon Sep 17 00:00:00 2001 From: Niko Hobart Date: Wed, 16 Oct 2024 15:14:20 -0700 Subject: [PATCH] added client side interceptors --- pkg/intercept/interceptors.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pkg/intercept/interceptors.go diff --git a/pkg/intercept/interceptors.go b/pkg/intercept/interceptors.go new file mode 100644 index 00000000..49908e01 --- /dev/null +++ b/pkg/intercept/interceptors.go @@ -0,0 +1,17 @@ +// Package intercept provides gRPC interceptors for MOCStack clients. +package intercept + +import ( + "context" + + "github.com/microsoft/moc/pkg/errors" + "google.golang.org/grpc" +) + +// NewErrorParsingInterceptor transforms grpc errors to moc errors +func NewErrorParsingInterceptor() grpc.UnaryClientInterceptor { + return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { + err := invoker(ctx, method, req, reply, cc, opts...) + return errors.ParseGRPCError(err) + } +}