return StatusCode::INTERNAL for proto parsing error

pull/2907/head
yang-g 9 years ago
parent 826f07eb6f
commit f99c090625
  1. 9
      src/cpp/proto/proto_utils.cc

@ -158,14 +158,13 @@ Status SerializeProto(const grpc::protobuf::Message& msg, grpc_byte_buffer** bp)
GrpcBufferWriter writer(bp);
return msg.SerializeToZeroCopyStream(&writer)
? Status::OK
: Status(StatusCode::INVALID_ARGUMENT,
"Failed to serialize message");
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}
Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,
int max_message_size) {
if (!buffer) {
return Status(StatusCode::INVALID_ARGUMENT, "No payload");
return Status(StatusCode::INTERNAL, "No payload");
}
GrpcBufferReader reader(buffer);
::grpc::protobuf::io::CodedInputStream decoder(&reader);
@ -173,11 +172,11 @@ Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,
decoder.SetTotalBytesLimit(max_message_size, max_message_size);
}
if (!msg->ParseFromCodedStream(&decoder)) {
return Status(StatusCode::INVALID_ARGUMENT,
return Status(StatusCode::INTERNAL,
msg->InitializationErrorString());
}
if (!decoder.ConsumedEntireMessage()) {
return Status(StatusCode::INVALID_ARGUMENT, "Did not read entire message");
return Status(StatusCode::INTERNAL, "Did not read entire message");
}
return Status::OK;
}

Loading…
Cancel
Save