Can we intercept an incoming grpc request (Java ) and send the response back gracefully

56 views
Skip to first unread message

anu....@gmail.com

unread,
May 1, 2019, 5:04:35 PM5/1/19
to grpc.io
Hi Friends,

We have gRPC server which receives the request, and based upon one specific validation, we want to return the request without sending it to service.

We implemented the below class..

public class MyInterceptor implements ServerInterceptor {

    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
            ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {

       if(!someCondition) {
         call.close(Status.UNKNOWN, headers);
         return new ServerCall.Listener<ReqT>() {};       
       
       }

        return next.startCall(call, headers);

    }


the problem with this code is that, at client end it gives the below error trace..

Exception in thread "main" io.grpc.StatusRuntimeException: UNKNOWN


can we send the proper response with error code so that client will get specific error code and not the above error message

Thanks in advance for your help and advice.
Regards
Anurag

Carl Mastrangelo

unread,
May 2, 2019, 1:21:11 PM5/2/19
to grpc.io
That sounds right.  You should really include an error message along with your status, but that is the way I would go about it.  I vaguely recall gRPC (the library) doing the same thing, but I can't find it at the moment.

Anurag Misra

unread,
May 2, 2019, 3:25:31 PM5/2/19
to grpc.io
Thanks Carl . If you find something, pls let us know.
Regards
Anurag
Reply all
Reply to author
Forward
0 new messages