sogou / srpc

RPC framework based on C++ Workflow. Supports SRPC, Baidu bRPC, Tencent tRPC, thrift protocols.
Apache License 2.0
1.96k stars 387 forks source link

应该如何正确的报错呢? #401

Open wxd237 opened 4 months ago

wxd237 commented 4 months ago

我没找到例子关于如何正确的给返回客户端,错误码和错误信息,这个应该如何弄比较优雅

  Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
    if (request->name().empty()) {
      return Status(grpc::StatusCode::INVALID_ARGUMENT, "Name must not be empty");
    }
    reply->set_message("Hello " + request->name());
    return Status::OK;
  }
};
Barenboim commented 4 months ago

这种情况,我觉得把错误码和错误字符串设计在你的协议里会好一些,因为这是一次正常的通信,没有办法在直接修改我们meta信息里的错误码。