GRPC exception handling

I have a server written in Java and a client written in PHP. How can a client throw an exception from the server if something goes wrong? I cannot find anything about exception handling in the gRPC documentation.

Thanks!

+4
source share
2 answers

For handled exceptions, call responseObserver.onError() . If you pass a StatusRuntimeException or a StatusException (usually status.asRuntimeException() using status.asRuntimeException() ), the status code and description will be passed to the client. Unhandled exceptions in the callback will cancel the RPC and will continue to throw an exception (usually leading to an UncaughtExceptionHandler call for the executor).

+4
source

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

The status here will have the code and details fields that will determine the response code and the corresponding message, if it is set as indicated in Eric's response. Based on the fact that appropriate error handling can be performed on the client.

+1
source

All Articles