booking-microservices/building-blocks/Exception/GrpcExceptionInterceptor.cs
2025-03-15 16:54:20 +03:30

24 lines
634 B
C#

using Grpc.Core;
using Grpc.Core.Interceptors;
using Microsoft.Extensions.Logging;
namespace BuildingBlocks.Exception;
public class GrpcExceptionInterceptor : Interceptor
{
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
TRequest request,
ServerCallContext context,
UnaryServerMethod<TRequest, TResponse> continuation)
{
try
{
return await continuation(request, context);
}
catch (System.Exception exception)
{
throw new RpcException(new Status(StatusCode.Internal, exception.Message));
}
}
}