Created
July 7, 2019 02:21
-
-
Save sat0yu/423e142c8c9367fcffb7b808ae444b17 to your computer and use it in GitHub Desktop.
sentry-raven-grpc/interceptor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ErrorCapturer specifies the implementation of a method to capture the given error | |
type ErrorCapturer interface { | |
CaptureError(err error, tags map[string]string) string | |
} | |
// SentryRavenInterceptor creates an interceptor which catches the errors from each service method and reports them to Sentry | |
func SentryRavenInterceptor(ec ErrorCapturer) grpc.UnaryServerInterceptor { | |
return func(ctx context.Context, req interface{}, _info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { | |
resp, err := handler(ctx, req) | |
if err != nil { | |
ec.CaptureError(err, nil) | |
} | |
return resp, err | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment