From d8e64ab5bf438c2a17efc5a1ab6589f2b4bad85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borja=20Garc=C3=ADa=20Rodr=C3=ADguez?= Date: Tue, 15 Dec 2020 12:53:43 +0100 Subject: [PATCH] interceptor in mobile bff --- .../Infrastructure/GrpcExceptionInterceptor.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs index 6dc0cfb1f..aa1d5ce6a 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs @@ -1,6 +1,8 @@ using Grpc.Core; using Grpc.Core.Interceptors; using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure { @@ -18,11 +20,18 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastruct ClientInterceptorContext context, AsyncUnaryCallContinuation continuation) { - _logger.LogInformation("Calling via grpc client base address serviceName={@ServiceName}, BaseAddress={@Host}", context.Method.ServiceName, context.Host); + var call = continuation(request, context); + return new AsyncUnaryCall(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose); + } + + private async Task HandleResponse(Task t) + { try { - return continuation(request, context); + var response = await t; + _logger.LogDebug($"Response received: {response}"); + return response; } catch (RpcException e) {