Browse Source

interceptor in mobile bff

pull/1547/head
Borja García Rodríguez 4 years ago
parent
commit
d8e64ab5bf
1 changed files with 11 additions and 2 deletions
  1. +11
    -2
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs

+ 11
- 2
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs 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.Mobile.Shopping.HttpAggregator.Infrastructure namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure
{ {
@ -18,11 +20,18 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastruct
ClientInterceptorContext<TRequest, TResponse> context, ClientInterceptorContext<TRequest, TResponse> context,
AsyncUnaryCallContinuation<TRequest, TResponse> continuation) AsyncUnaryCallContinuation<TRequest, TResponse> 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<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)
{ {


Loading…
Cancel
Save