catch error with interceptor

This commit is contained in:
Borja García Rodríguez 2020-12-15 12:35:47 +01:00
parent b67a487f2c
commit f26e27bd4e

View File

@ -1,6 +1,8 @@
using Grpc.Core; using Grpc.Core;
using Grpc.Core.Interceptors; using Grpc.Core.Interceptors;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
{ {
@ -17,10 +19,19 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
TRequest request, TRequest request,
ClientInterceptorContext<TRequest, TResponse> context, ClientInterceptorContext<TRequest, TResponse> context,
AsyncUnaryCallContinuation<TRequest, TResponse> continuation) AsyncUnaryCallContinuation<TRequest, TResponse> continuation)
{
var call = continuation(request, context);
return new AsyncUnaryCall<TResponse>(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose);
}
private async Task<TResponse> HandleResponse<TResponse>(Task<TResponse> t)
{ {
try try
{ {
return continuation(request, context); var response = await t;
_logger.LogDebug($"Response received: {response}");
return response;
} }
catch (RpcException e) catch (RpcException e)
{ {