From f26e27bd4e80fe1dde87685cc1e14421cde77fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borja=20Garc=C3=ADa=20Rodr=C3=ADguez?= Date: Tue, 15 Dec 2020 12:35:47 +0100 Subject: [PATCH] catch error with interceptor --- .../Infrastructure/GrpcExceptionInterceptor.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs index 2bbe69cf5..3120a3567 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs +++ b/src/ApiGateways/Web.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.Web.Shopping.HttpAggregator.Infrastructure { @@ -17,10 +19,19 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure TRequest request, ClientInterceptorContext context, AsyncUnaryCallContinuation continuation) + { + 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) {