Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wxd237 opened this issue Jul 18, 2024 · 1 comment
Open

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

wxd237 opened this issue Jul 18, 2024 · 1 comment

Comments

@wxd237
Copy link

wxd237 commented Jul 18, 2024

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

  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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants