A wrapper around google::rpc::Status that provides a convenient API for creating and managing gRPC status responses with rich error details.
Documentation:
- See also
- RichStatus
RichStatus allows you to create gRPC status responses with structured error information conforming to the Google RPC error model. It supports adding multiple error details of various types to provide comprehensive error information to clients.
- See also
- https://google.aip.dev/193
-
https://grpc.io/docs/guides/error/
-
ugrpc::ErrorInfo
-
ugrpc::RetryInfo
-
ugrpc::DebugInfo
-
ugrpc::QuotaFailure
-
ugrpc::PreconditionFailure
-
ugrpc::BadRequest
-
ugrpc::RequestInfo
-
ugrpc::ResourceInfo
-
ugrpc::Help
-
ugrpc::LocalizedMessage
Example usage:
SayHelloResult SayHello(CallContext& , sample::ugrpc::GreetingRequest&& ) override {
ugrpc::RichStatus rich_status{
grpc::StatusCode::RESOURCE_EXHAUSTED,
"message",
ugrpc::Help{{{.description = "test_url", .url = "http://help.url/auth/fts-documentation/tvm"}}},
ugrpc::QuotaFailure{{{.subject = "123-pipepline000", .description = "fts quota [fts-receive] exhausted"}}},
};
return rich_status.ToGrpcStatus();
}
Definition at line 43 of file rich_status.hpp.
template<typename TRichErrorDetail>
| std::optional< TRichErrorDetail > ugrpc::RichStatus::TryGetDetail |
( |
const google::rpc::Status & | status | ) |
|
|
staticnodiscard |
Attempts to extract a specific rich error detail from google::rpc::Status
- Returns
- The extracted rich error detail if found,
std::nullopt otherwise
According to AIP-193 (https://google.aip.dev/193), each status should contain at most one detail of each type. If multiple details of the same type exist (violating AIP-193), this function will return only the first encountered instance.
Example usage:
UTEST_F(GrpcClientWithDetailedRichErrorTest, TryGetErrorDetail) {
sample::ugrpc::GreetingRequest out;
out.set_name("userver");
try {
GetClient().SayHello(out);
FAIL() << "Expected ResourceExhaustedError";
const auto& status = e.GetStatus();
EXPECT_TRUE(gstatus.has_value());
EXPECT_TRUE(help_detail.has_value());
EXPECT_EQ(help_detail->links.size(), 1);
EXPECT_EQ(help_detail->links[0].description, "test_url");
EXPECT_EQ(help_detail->links[0].url, "http://help.url/auth/fts-documentation/tvm");
EXPECT_TRUE(quota_failure_detail.has_value());
EXPECT_EQ(quota_failure_detail->violations.size(), 1);
EXPECT_EQ(quota_failure_detail->violations[0].subject, "123-pipepline000");
EXPECT_EQ(quota_failure_detail->violations[0].description, "fts quota [fts-receive] exhausted");
}
}
Definition at line 391 of file rich_status.hpp.