Why does throwning an exception in the server-side Interceptor not cause an exception caught in aspnetcore middleware?
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 836
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 7
Description
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 UnaryServerHandler(
TRequest request,
ServerCallContext context,
UnaryServerMethod 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.
Contributor guide
Research direction
Start with the server-side UnaryServerHandler interceptor and the ASP.NET Core middleware Invoke method shown in the issue. Trace what happens after continuation completes and determine the expected exception propagation behavior; done means clearly documenting or correcting the observed behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100