What is the correct way of processing when grpc::StatusCode are overlapped with service's response?

32 views
Skip to first unread message

xiaona...@gmail.com

unread,
Sep 7, 2017, 5:32:01 AM9/7/17
to grpc.io
Hi all,

Greetings from me! I am a newbie of using gPRC, and my service is so simple:  

service KeyDB {
rpc Init(InitRequest) returns (InitResponse) {}
}

enum ServerResponse {
SUCCESS = 0;
ALREADY_EXISTS = 1;
}

message InitRequest {
bytes pub_key = 1;
}

message InitResponse {
ServerResponse response = 1;
}

The client just sends pub_key, and servers responses SUCCESS or key ALREADY_EXISTS.
I find the ServerResponse code is very similar as grpc::StatusCode. So my Server::Init
function always returns OK, and uses response to carry error code.

grpc::Status Server::Init(grpc::ServerContext* context, request, response)
{
   ......
response.set_response(ALREADY_EXISTS);
......
return grpc::Status()
}
So is there any canonical way of processing when grpc::StatusCode are partly or all overlapped 
with service's response? Or are there any better solutions?

Thanks very much in advance!

Best Regards
Nan Xiao

Yuchen Zeng

unread,
Oct 24, 2017, 5:14:43 PM10/24/17
to grpc.io
Hi Nan,

ALREADY_EXISTS is never generated by the gRPC library. You can return this status from your service implementation. Please check https://github.com/grpc/grpc/blob/master/doc/statuscodes.md for more information.

Thanks,
Yuchen
Reply all
Reply to author
Forward
0 new messages