From 20b9de6b76982e5bcc382747b1a14af6faaee44f Mon Sep 17 00:00:00 2001 From: Hamed Shirbandi Date: Wed, 4 Oct 2023 21:55:37 +0200 Subject: [PATCH] fix: log error in grpc global exception handler --- .../Web.MVC/Exceptions/GrpcGlobalExceptionHandler.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/1-BuildingBlocks/Web.MVC/Exceptions/GrpcGlobalExceptionHandler.cs b/src/1-BuildingBlocks/Web.MVC/Exceptions/GrpcGlobalExceptionHandler.cs index 054181578..0a42e5dca 100644 --- a/src/1-BuildingBlocks/Web.MVC/Exceptions/GrpcGlobalExceptionHandler.cs +++ b/src/1-BuildingBlocks/Web.MVC/Exceptions/GrpcGlobalExceptionHandler.cs @@ -1,5 +1,6 @@ using Grpc.Core; using Grpc.Core.Interceptors; +using Microsoft.Extensions.Logging; namespace TaskoMask.BuildingBlocks.Web.MVC.Exceptions { @@ -8,6 +9,13 @@ namespace TaskoMask.BuildingBlocks.Web.MVC.Exceptions /// public class GrpcGlobalExceptionHandler : Interceptor { + private readonly ILogger _logger; + + public GrpcGlobalExceptionHandler(ILogger logger) + { + this._logger = logger; + } + public override async Task UnaryServerHandler( TRequest request, ServerCallContext context, @@ -19,6 +27,8 @@ public override async Task UnaryServerHandler( } catch (Exception exception) { + _logger.LogError(exception, exception.Message); + throw new RpcException(new Status(StatusCode.Cancelled, exception.Message)); } }