grpc-dotnet
grpc-dotnet copied to clipboard
Why does throwning an exception in the server-side Interceptor not cause an exception caught in aspnetcore middleware?
Hello, I have trouble understanding the behavior of the GRPC interceptors. I thought it would act in a similar way as netcore middleware, i.e. that if I throw an exception in it, e.g. like that:
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
TRequest request,
ServerCallContext context,
UnaryServerMethod<TRequest, TResponse> continuation)
{
await continuation(request, context);
throw new InvalidOperationException("FOO"); //or RpcException
}
this exception would be caught by the middleware that is executed before the GRPC middleware, e.g.
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception exception)
{
//expected some kind of FOO error here
}
}
however, instead the await _next(context)
finishes without problems and the error is only caught by the grpc client side code.