Skip to content
Advertisement

What is the proper way to return an error from gRPC ServerInterceptor

I have a Quarkus application that uses gRPC. I have implemented a ServerInterceptor to look for and validate auth tokens.

JavaScript

This works and sends a message to the client like this:

JavaScript

but it logs this error on the server because I didn’t return from the method after sending the error:

JavaScript

Several posts suggest I can return an empty ServerCall.Listener like this:

JavaScript

this works and gets rid of the server-side error message BUT it breaks the message returned to the client. The client just gets this:

JavaScript

So my question is: how do I return a meaningful error message to the client and not log an exception server-side?

Advertisement

Answer

You could catch it all in a try block and send the message just in there; The issue you face is that you are first closing the call before returning it, so it tries to process an already closed pipe.

In the second scenario, as you send the “void” message right after the “close” message, the detailed message gets overriden.

Try something like:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement