Exception handling in gRPC

人走茶凉 提交于 2019-12-22 05:48:15

问题


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!


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




回答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.



来源:https://stackoverflow.com/questions/38810657/exception-handling-in-grpc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!