This is exactly what I'm trying to avoid - unwrapping 
StatusRuntimeException each time I expect an exception or each time I call 
a grpc stub method.
What I want is to setup an exception converter once, and have it applied 
automatically to all grpc calls.

On Thursday, March 29, 2018 at 7:00:07 PM UTC+3, Carl Mastrangelo wrote:
> Point of clarification:   Stubs throw exceptions, Calls and Call.Listeners 
> do not.   The stubs wrap the calls/listeners and convert Status and 
> Metadata trailers into an exception, but you don't have to.   
> In the code you linked, you can attach a cause to the Status and pass that 
> through in your interceptor.   The outer most exception the stub will get 
> is a StatusRuntimeException IIRC, but you can walk the causal chain to get 
> at your underlying.  (we don't really /throw/ other people's exceptions)
> On Thursday, March 1, 2018 at 11:35:58 AM UTC-8, wrote:
>> Carl,
>> thanks for reply.
>> However, I'm a bit confused as I don't see a way to return my custom 
>> exception from the listener to the calling code.
>> Throwing an exception from onClose simply swallows the exception and 
>> makes the call hang forever.
>> super.onClose() only accepts status and trailers. So, no way to pass my 
>> custom exception.
>> I added client 
>> <>
>> interceptor to the example project.
>> Regards,
>> Eduard
>> On Thursday, March 1, 2018 at 9:45:20 PM UTC+3, Carl Mastrangelo wrote:
>>> You need to add a ClientInterceptor too.  It will provide a listener 
>>> which overrides the onClose(Status, Metadata) method of a 
>>> ClientCall.Listener.    There, you can check for your metadata row added by 
>>> the server, and return the proper type of error to the next listener in 
>>> your interceptor chain.
>>> On Thursday, March 1, 2018 at 1:10:36 AM UTC-8, 
>>> wrote:
>>>> Here's the example that shows what I'm trying to achieve - 
>>>> The idea is the following:
>>>> I have a set of domain exception known by each microservice. There's a 
>>>> mapping domain exception <-> StatusRuntimeException
>>>> Server automatically converts domain exception into 
>>>> StatusRuntimeException. That's done by server interceptor.
>>>> And I'd like to convert it back to domain exception on the client side, 
>>>> so that calling code does not need to worry about StatusRuntimeException 
>>>> at 
>>>> all and only works with domain exceptions.
>>>> Thanks in advance.
>>>> Regards,
>>>> Eduard
>>>> On Wednesday, February 14, 2018 at 10:01:36 PM UTC+3, Carl Mastrangelo 
>>>> wrote:
>>>>> No updates.   If you can upload your code somewhere, it would be 
>>>>> clearer why the interceptor wouldn't work.  
>>>>> On Friday, February 9, 2018 at 5:52:34 AM UTC-8, 
>>>>> wrote:
>>>>>> Hi!
>>>>>> Any updates on this?
>>>>>> I checked version 1.9.0 and still don't see a way to do exception 
>>>>>> conversion in an interceptor. 
>>>>>> I now think of writing my own wrappers for all blocking stubs to 
>>>>>> perform exception conversion. That would allow not to check status codes 
>>>>>> across the application and just catch specific exceptions where needed.
>>>>>> However, having the ability to define an exception transformer 
>>>>>> globally for grpc client would of course make life easier.
>>>>>> Thanks

NOTICE: This email and files attached to it are 
confidential. If you
are not the intended recipient you are hereby notified 
that using,
copying, distributing or taking any action in reliance on the 
contents of this information is strictly prohibited. If you have
this email in error please notify the sender and delete this

You received this message because you are subscribed to the Google Groups 
"" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

Reply via email to