Skip to content

Commit

Permalink
update logger
Browse files Browse the repository at this point in the history
  • Loading branch information
gimmyxd committed May 15, 2024
1 parent 77e7cb5 commit 9edd09c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions grpcutil/middlewares/gerr/gerr_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
"google.golang.org/grpc/status"
)

type ErrorMiddleware struct {
}
type ErrorMiddleware struct{}

func NewErrorMiddleware() *ErrorMiddleware {
return &ErrorMiddleware{}
Expand Down Expand Up @@ -50,6 +49,10 @@ func (m *ErrorMiddleware) handleError(ctx context.Context, handlerErr error) err
}

log := zerolog.Ctx(ctx)
if errorLogger := errors.Logger(handlerErr); errorLogger != nil {
log = errorLogger
}

if log == nil {
fmt.Printf("ERROR - ZEROLOG LOGGER MISSING FROM CONTEXT: %v\n", handlerErr)
return status.New(codes.Internal, "internal logging error, please contact the administrator").Err()
Expand All @@ -70,11 +73,6 @@ func (m *ErrorMiddleware) handleError(ctx context.Context, handlerErr error) err
asertoErr = errors.ErrUnknown
}

errorLogger := errors.Logger(handlerErr)
if errorLogger != nil {
log = errorLogger
}

asertoErr = asertoErr.Int(errors.HTTPStatusErrorMetadata, asertoErr.HTTPCode)

log.Warn().Stack().Err(handlerErr).
Expand Down

0 comments on commit 9edd09c

Please sign in to comment.