userver-framework / userver

Production-ready C++ Asynchronous Framework with rich functionality
https://userver.tech
Apache License 2.0
2.36k stars 272 forks source link

Add support to get `grpc::StatusCode` from `stream.Finish()` #554

Open root-kidik opened 4 months ago

root-kidik commented 4 months ago

pg_grpc_service_template

// Initiate the RPC. No actual actions have been taken thus far besides
// preparing to send the request.
auto stream = client_.SayHello(request, std::move(context));

Now:

try
{
    auto response = client_.SayHello(request, std::move(context)).Finish();
}
catch (const ugrpc::client::RpcError&)
{
    // ...
}

After:

if (auto result = client_.SayHello(request, std::move(context)).FinishWithError(); result.has_value())
    // ... result.value()
else
    // ... result.error()