stepancheg / grpc-rust

Rust implementation of gRPC
MIT License
1.38k stars 125 forks source link

ServerResponseUnarySink sent GrpcStatus error code but client failed to recognize #187

Closed pwang7 closed 3 years ago

pwang7 commented 3 years ago

Hi all,

I have a huge proto file, and I used grpc-rust to generate the server and client code, which used ServerResponseUnarySink to send response. I use the send_grpc_error method of ServerResponseUnarySink to send GrpcStatus error code to the client. But the client cannot recognize the error code, no matter what the error code is, the client read all GrpcStatus error code as GrpcStatus::Unknown.

Here is how I send error code:

    fn get_capacity(
        &self,
        _o: ServerHandlerContext,
        _req: ServerRequestSingle<GetCapacityRequest>,
        resp: ServerResponseUnarySink<GetCapacityResponse>,
    ) -> grpc::Result<()> {
        resp.send_grpc_error(GrpcStatus::Unimplemented, String::new("GetCapacity is unimplemented"))
    }

Here is the proto snippet:

service Controller { 
  rpc GetCapacity (GetCapacityRequest)
    returns (GetCapacityResponse) {}
  ......
}

Am I sending the GrpcStatus error code in the right way? BTW, why not grpc-rust generated server and client code using SingleResponse?

Thanks!

pwang7 commented 3 years ago

I found out the reason:

the Headers in headers_500 function miss content-type field, whereas the Headers in headers_200 function do have content-type field.