Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 481
Kevin Avatar asked Aug 07 '16 03:08

Kevin


People also ask

How does exception handle in gRPC?

To that end, always use StreamObserver::OnError, which internally adds the status error to the trailing headers. The only exception, as we'll see below, is when we're working with streams. All client or server gRPC libraries support the official gRPC error model. Java encapsulates this error model with the class io.

What is blocking stub in gRPC?

a blocking/synchronous stub: this means that the RPC call waits for the server to respond, and will either return a response or raise an exception. a non-blocking/asynchronous stub that makes non-blocking calls to the server, where the response is returned asynchronously.

Is gRPC over HTTP or TCP?

gRPC uses HTTP/2, which multiplexes multiple calls on a single TCP connection. All gRPC calls over that connection go to one endpoint.

Can gRPC server call client?

Using the API Starting from a service definition in a . proto file, gRPC provides protocol buffer compiler plugins that generate client- and server-side code. gRPC users typically call these APIs on the client side and implement the corresponding API on the server side.


1 Answers

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

like image 83
Eric Anderson Avatar answered Sep 26 '22 04:09

Eric Anderson