How to define a global error handler in gRPC python

后端 未结 3 1828
眼角桃花
眼角桃花 2021-02-09 11:11

Im trying to catch any exception that is raised in any servicer so I can make sure that I only propagate known exceptions and not unexpected ones like ValueError, TypeError etc.

3条回答
  •  眼角桃花
    2021-02-09 11:47

    gRPC Python currently don't support server-side global error handler. The interceptor won't execute the server handler inside the intercept_service function, so there is no way to try/except.

    Also, I found the gRPC Python server interceptor implementation is different from what they proposed original at L13-Python-Interceptors.md#server-interceptors. If the implementation stick to the original design, we can use interceptor as global error handler easily with handler and request/request_iterator.

    # Current Implementation
    intercept_service(self, continuation, handler_call_details)
    
    # Original Design
    intercept_unary_unary_handler(self, handler, method, request, servicer_context)
    intercept_unary_stream_handler(self, handler, method, request, servicer_context)
    intercept_stream_unary_handler(self, handler, method, request_iterator, servicer_context)
    intercept_stream_stream_handler(self, handler, method, request_iterator, servicer_context)
    

    Please submit a feature request issue to https://github.com/grpc/grpc/issues.

提交回复
热议问题