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, [email protected] 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 
> <https://github.com/cartmanez/grpc-java-by-example/blob/master/error-handling-example/error-handling-client/src/main/java/com/example/grpc/client/ClientExceptionHandlingInterceptor.java>
>  
> 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, [email protected] wrote:
>>>
>>> Here's the example that shows what I'm trying to achieve - 
>>> https://github.com/cartmanez/grpc-java-by-example/tree/master/error-handling-example
>>> 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, [email protected] 
>>>> 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
>>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/65827f38-bff1-4095-93d5-98e0c2bf2430%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to