0
votes

Im trying to intercept exceptions io.grpc.StatusRuntimeException thrown by the GRPC stub, and turn them into RESt exceptions. I need to implement the ClientInterceptor not sure how?

2

2 Answers

0
votes

You can't in an Interceptor. The gRPC stub and core library will remap exceptions to StatusRuntimeException. Interceptors are meant to let you modify the request and response, but still are surfaced via the gRPC API.

You can write your own stub wrapper (perhaps using AbstractStub), to remap these exceptions.

0
votes

I had the same issue, and it cannot be done because onMessage method will catch any throwable into StatusRuntimException and the status will be cancel.

https://github.com/grpc/grpc-java/issues/3434

So in my case, server and client should use some kind of standard like code(HTTP CODE) and message. so in service layer, check if the response code != 200 then throw your Exception from the code and message from server

And my post was replied by Carl Mastrangelo too :)