Returning null from a grpc interceptor when there is a failure status code
See original GitHub issueWhy can’t return null from an interceptor there is a failure status code.
public class TestInterceptor : Interceptor
{
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation)
{
if (Some Logic)
{
return await continuation(request, context);
}
context.Status = new Status(StatusCode.Unavailable, "Some information about the issue");
return null!;
}
}
I don’t think I’m supposed to return a response when there is a failure status code. Or do I? When I return null with failure status code I get this error message
Grpc.Core.RpcException: Status(StatusCode="Cancelled", Detail="No message returned from method.")
at Grpc.AspNetCore.Server.Internal.CallHandlers.UnaryServerCallHandler`3.HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:16 (9 by maintainers)
Top Results From Across the Web
java - What is the proper way to return an error from gRPC ...
I have a Quarkus application that uses gRPC. I have implemented a ServerInterceptor to look for and validate auth tokens. @ApplicationScoped ...
Read more >Getting Error Handling right in gRPC
gRPC has limited built-in error handling based on simple status codes and metadata, ... so error.getCause() on the client is effectively returning null...
Read more >Getting Error Handling right in gRPC | by Pankaj Kumar
By default, gRPC relies heavily on status code for error handling. ... so error.getCause() on the client is effectively returning null .
Read more >How to handle gRPC errors in .Net Core - the-worst.dev
Handling gRPC server exceptions in .Net Core. Changing of gRPC requests HTTP status code for bad requests. Transform gRPC exception details ...
Read more >Error Handling in gRPC
In this tutorial, we'll focus on gRPC error handling using Java. gRPC has very low latency and high throughput, so it's ideal to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We use MessagePack for
Marshaller
instead of protobuf, so it is possible to serializenull
. This means that a Unary method implementation that returnsnull
asTResponse
inMethod<TRequest, TResponse>
can still send a message body.However, as discussed here, Grpc.AspNetCore.Server will block if it receives
null
.😢gRPC doesn’t use exceptions in typical application flow. If an HTTP request is being canceled, causing gRPC to throw a RpcException, an exception being thrown will have no impact at all on performance.