Exception handling in gRPC

10,598

Solution 1

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).

Solution 2

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.

Share:
10,598
Kevin
Author by

Kevin

Updated on June 27, 2022

Comments

  • Kevin
    Kevin almost 2 years

    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!