Kevin
Kevin

Reputation: 1569

Exception handling in gRPC

I have a server written in Java and client written in PHP. How can client catch exception from server if anything goes wrong? I can't find anything about exception handling in gRPC documentation.

Thank you!

Upvotes: 8

Views: 12114

Answers (2)

Ronil Merchant
Ronil Merchant

Reputation: 31

In the response at the client side (php) http://www.grpc.io/grpc/php/source-class-Grpc.UnaryCall.html#82

the status here will have the code and details fields which will determine the response code and the appropriate message if set as mentioned in Eric's response. Based on that appropriate error handling can be done at the client.

Upvotes: 1

Eric Anderson
Eric Anderson

Reputation: 26414

For handled exceptions, call responseObserver.onError(). If you pass in a StatusRuntimeException or StatusException (generally created via status.asRuntimeException()) the status code and description will be communicated to the client. Unhandled exceptions within a callback will cancel the RPC and will continue propagating the exception (generally leading in an UncaughtExceptionHandler being called for the executor).

Upvotes: 8

Related Questions