mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
fix: grpc status in sentry and validation interceptors (#2012)
This commit is contained in:
parent
da181b9e8c
commit
87ef8f454a
@ -6,8 +6,7 @@ import (
|
||||
"github.com/getsentry/sentry-go"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/grpc/errors"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func SentryHandler() grpc.UnaryServerInterceptor {
|
||||
@ -18,8 +17,17 @@ func SentryHandler() grpc.UnaryServerInterceptor {
|
||||
|
||||
func sendErrToSentry(ctx context.Context, req interface{}, handler grpc.UnaryHandler) (interface{}, error) {
|
||||
resp, err := handler(ctx, req)
|
||||
code, _, _, _ := errors.ExtractCaosError(err)
|
||||
if code == codes.Unknown || code == codes.Internal {
|
||||
code := status.Code(err)
|
||||
switch code {
|
||||
case codes.Canceled,
|
||||
codes.Unknown,
|
||||
codes.DeadlineExceeded,
|
||||
codes.ResourceExhausted,
|
||||
codes.Aborted,
|
||||
codes.Unimplemented,
|
||||
codes.Internal,
|
||||
codes.Unavailable,
|
||||
codes.DataLoss:
|
||||
sentry.CaptureException(err)
|
||||
}
|
||||
return resp, err
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
_ "github.com/caos/zitadel/internal/statik"
|
||||
)
|
||||
@ -25,7 +27,7 @@ func validate(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
||||
}
|
||||
err := validate.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
return handler(ctx, req)
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ func CreateServer(verifier *authz.TokenVerifier, authConfig authz.Config, lang l
|
||||
grpc_middleware.ChainUnaryServer(
|
||||
middleware.DefaultTracingServer(),
|
||||
middleware.MetricsHandler(metricTypes, grpc_api.Probes...),
|
||||
middleware.SentryHandler(),
|
||||
middleware.ErrorHandler(),
|
||||
middleware.AuthorizationInterceptor(verifier, authConfig),
|
||||
middleware.SentryHandler(),
|
||||
middleware.TranslationHandler(lang),
|
||||
middleware.ValidationHandler(),
|
||||
middleware.ServiceHandler(),
|
||||
|
Loading…
Reference in New Issue
Block a user