#include <userver/ugrpc/rich_status.hpp>
A wrapper around google::rpc::Status that provides a convenient API for creating and managing gRPC status responses with rich error details.
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:
Definition at line 41 of file rich_status.hpp.
|
| template<typename TRichErrorDetail> |
| static std::optional< TRichErrorDetail > | TryGetDetail (const google::rpc::Status &status) |
| | Attempts to extract a specific rich error detail from google::rpc::Status
|
| |
◆ RichStatus() [1/2]
| ugrpc::RichStatus::RichStatus |
( |
const grpc::Status & | grpc_status | ) |
|
|
explicit |
Constructs a RichStatus from a grpc::Status.
- Parameters
-
| grpc_status | The gRPC status to convert. If it contains serialized google::rpc::Status in error_details(), it will be parsed and used. |
◆ RichStatus() [2/2]
template<typename... TDetails>
| ugrpc::RichStatus::RichStatus |
( |
grpc::StatusCode | code, |
|
|
std::string | message, |
|
|
TDetails &&... | details ) |
Constructs a RichStatus with the given code, message, and details.
- Parameters
-
| code | The gRPC status code |
| message | The error message |
| details | Error details conforming to google.rpc.error_details types. Must have a ToGoogleErrorDetail() method. |
Definition at line 375 of file rich_status.hpp.
◆ AddDetail()
template<typename TDetail>
| RichStatus & ugrpc::RichStatus::AddDetail |
( |
TDetail && | detail | ) |
|
Adds an error detail to the status.
- Parameters
-
| detail | The error detail to add. Must have a ToGoogleErrorDetail() method. |
- Returns
- Reference to this
RichStatus for method chaining.
Definition at line 382 of file rich_status.hpp.
◆ GetGoogleStatus() [1/2]
| google::rpc::Status ugrpc::RichStatus::GetGoogleStatus |
( |
| ) |
&& |
|
inline |
◆ GetGoogleStatus() [2/2]
| const google::rpc::Status & ugrpc::RichStatus::GetGoogleStatus |
( |
| ) |
const & |
|
inlinenodiscard |
◆ operator grpc::Status()
| ugrpc::RichStatus::operator grpc::Status |
( |
| ) |
const |
|
inlineexplicitnodiscard |
◆ ToGrpcStatus()
| grpc::Status ugrpc::RichStatus::ToGrpcStatus |
( |
| ) |
const |
|
nodiscard |
Converts this RichStatus to a grpc::Status.
- Returns
- A
grpc::Status with serialized error details.
◆ TryGetDetail()
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:
Definition at line 389 of file rich_status.hpp.
The documentation for this class was generated from the following file: