Skip to content

Commit

Permalink
fix: log error in grpc global exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-shirbandi committed Oct 4, 2023
1 parent ef259a5 commit 20b9de6
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Grpc.Core;
using Grpc.Core.Interceptors;
using Microsoft.Extensions.Logging;

namespace TaskoMask.BuildingBlocks.Web.MVC.Exceptions
{
Expand All @@ -8,6 +9,13 @@ namespace TaskoMask.BuildingBlocks.Web.MVC.Exceptions
/// </summary>
public class GrpcGlobalExceptionHandler : Interceptor
{
private readonly ILogger _logger;

public GrpcGlobalExceptionHandler(ILogger logger)
{
this._logger = logger;
}

public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
TRequest request,
ServerCallContext context,
Expand All @@ -19,6 +27,8 @@ public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
}
catch (Exception exception)
{
_logger.LogError(exception, exception.Message);

throw new RpcException(new Status(StatusCode.Cancelled, exception.Message));
}
}
Expand Down

0 comments on commit 20b9de6

Please sign in to comment.