diff --git a/README.md b/README.md index 1e1d9e1..4477b76 100644 --- a/README.md +++ b/README.md @@ -41,28 +41,28 @@ class ExceptionToStatusInterceptor(ServerInterceptor): def intercept( self, method: Callable, - request: Any, + request_or_iterator: Any, context: grpc.ServicerContext, method_name: str, ) -> Any: """Override this method to implement a custom interceptor. - You should call method(request, context) to invoke the + You should call method(request_or_iterator, context) to invoke the next handler (either the RPC method implementation, or the next interceptor in the list). Args: method: The next interceptor, or method implementation. - request: The RPC request, as a protobuf message. + request_or_iterator: The RPC request, as a protobuf message. context: The ServicerContext pass by gRPC to the service. method_name: A string of the form "/protobuf.package.Service/Method" Returns: This should generally return the result of - method(request, context), which is typically the RPC + method(request_or_iterator, context), which is typically the RPC method response, as a protobuf message. The interceptor is free to modify this in some way, however. """ try: - return method(request, context) + return method(request_or_iterator, context) except GrpcException as e: context.set_code(e.status_code) context.set_details(e.details) diff --git a/docs/index.rst b/docs/index.rst index b410b68..ed2b556 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -77,31 +77,31 @@ To define your own server interceptor (we can use a simplified version of def intercept( self, method: Callable, - request: Any, + request_or_iterator: Any, context: grpc.ServicerContext, method_name: str, ) -> Any: """Override this method to implement a custom interceptor. - You should call method(request, context) to invoke the + You should call method(request_or_iterator, context) to invoke the next handler (either the RPC method implementation, or the next interceptor in the list). Args: method: The next interceptor, or method implementation. - request: The RPC request, as a protobuf message. + request_or_iterator: The RPC request, as a protobuf message. context: The ServicerContext pass by gRPC to the service. method_name: A string of the form "/protobuf.package.Service/Method" Returns: This should generally return the result of - method(request, context), which is typically the RPC + method(request_or_iterator, context), which is typically the RPC method response, as a protobuf message. The interceptor is free to modify this in some way, however. """ try: - return method(request, context) + return method(request_or_iterator, context) except GrpcException as e: context.set_code(e.status_code) context.set_details(e.details) diff --git a/src/grpc_interceptor/server.py b/src/grpc_interceptor/server.py index d399ac7..6cd6ebc 100644 --- a/src/grpc_interceptor/server.py +++ b/src/grpc_interceptor/server.py @@ -24,8 +24,8 @@ def intercept( ) -> Any: # pragma: no cover """Override this method to implement a custom interceptor. - You should call method(request, context) to invoke the next handler (either the - RPC method implementation, or the next interceptor in the list). + You should call method(request_or_iterator, context) to invoke the next handler + (either the RPC method implementation, or the next interceptor in the list). Args: method: Either the RPC method implementation, or the next interceptor in @@ -37,7 +37,7 @@ def intercept( method_name: A string of the form "/protobuf.package.Service/Method" Returns: - This should generally return the result of method(request, context), which + This should return the result of method(request, context), which is typically the RPC method response, as a protobuf message, or an iterator of protobuf messages for streaming responses. The interceptor is free to modify this in some way, however. @@ -90,7 +90,7 @@ async def intercept( ) -> Any: # pragma: no cover """Override this method to implement a custom interceptor. - You should call await method(request_or_iterator, context) to invoke the next handler + You should await method(request_or_iterator, context) to invoke the next handler (either the RPC method implementation, or the next interceptor in the list). Args: @@ -103,7 +103,7 @@ async def intercept( method_name: A string of the form "/protobuf.package.Service/Method" Returns: - This should generally return the result of await method(request_or_iterator, context), + This should return the result of method(request_or_iterator, context), which is typically the RPC method response, as a protobuf message. The interceptor is free to modify this in some way, however. """