Hi,
I've been trying ascertain the correct way to handle error behaviour from streaming endpoints.
My code effectively does the following:
service MyService {
rpc StreamEndpoint(Request) returns (stream Response)
}
message Request {
repeated string query_ids = 1;
}
message Response {
string object_id = 1;
}
class MyService(MyServiceServicer):
def StreamEndpoint(self, request, context):
if not request.query_ids:
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
context.set_details('Must set at least one id')
yield Empty()
for obj in self.db.query(id_list=request.query_ids):
yield obj.to_protobuf()
I was expecting the client upon calling StreamEndpoint without query_ids to throw an RpcError (the client is also in Python) upon getting a code that isn't OK. However, it doesn't, even though the code in the response is correctly set to INVALID_ARGUMENT.
Is this the correct behaviour? If so, what is usually the recommended way of handling these errors in python, as I have relied on the exception on non-streaming endpoints.
Thanks