From 4218e423ce3ea435e365c51a615c2ca6aacb5bcd Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Sat, 17 Dec 2022 00:09:51 +0800 Subject: [PATCH] update auth --- pkg/interceptor/interceptor.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/interceptor/interceptor.go b/pkg/interceptor/interceptor.go index 93e5121..e55d2bb 100644 --- a/pkg/interceptor/interceptor.go +++ b/pkg/interceptor/interceptor.go @@ -25,16 +25,25 @@ func NewInterceptor(name string, urlWhitelist map[string]int) grpc.UnaryServerIn logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), zap.Any("resp", resp), zap.Error(err)) - //resp, err = handleWithAuth(ctx, req, info, handler, urlWhitelist) - //logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), - // zap.Any("resp", resp), zap.Error(err)) - s, _ := status.FromError(err) if s.Code() != 0 && s.Code() < 1000 { md, _ := metadata.FromIncomingContext(ctx) logger.Logger.Error(name, zap.String("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(s))) } + if err != nil { + return + } + + resp, err = handleWithAuth(ctx, req, info, handler, urlWhitelist) + logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), + zap.Any("resp", resp), zap.Error(err)) + s, _ = status.FromError(err) + if s.Code() != 0 && s.Code() < 1000 { + md, _ := metadata.FromIncomingContext(ctx) + logger.Logger.Error(name, zap.String("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), + zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(s))) + } return } }