#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.
Documentation:
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.
Definition at line 43 of file rich_status.hpp.
Public Member Functions | |
| RichStatus ()=default | |
Constructs an OK status with no error details. | |
| RichStatus (const grpc::Status &grpc_status) | |
Constructs a RichStatus from a grpc::Status. | |
| template<typename... TDetails> | |
| RichStatus (grpc::StatusCode code, std::string message, TDetails &&... details) | |
Constructs a RichStatus with the given code, message, and details. | |
| template<typename TDetail> | |
| RichStatus & | AddDetail (TDetail &&detail) |
| Adds an error detail to the status. | |
| const google::rpc::Status & | GetGoogleStatus () const & |
| google::rpc::Status | GetGoogleStatus () && |
| grpc::Status | ToGrpcStatus () const |
Converts this RichStatus to a grpc::Status. | |
| operator grpc::Status () const | |
Static Public Member Functions | |
| 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 | |
|
explicit |
Constructs a RichStatus from a grpc::Status.
| grpc_status | The gRPC status to convert. If it contains serialized google::rpc::Status in error_details(), it will be parsed and used. |
| ugrpc::RichStatus::RichStatus | ( | grpc::StatusCode | code, |
| std::string | message, | ||
| TDetails &&... | details ) |
Constructs a RichStatus with the given code, message, and details.
| 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 377 of file rich_status.hpp.
| RichStatus & ugrpc::RichStatus::AddDetail | ( | TDetail && | detail | ) |
Adds an error detail to the status.
| detail | The error detail to add. Must have a ToGoogleErrorDetail() method. |
RichStatus for method chaining. Definition at line 384 of file rich_status.hpp.
|
inline |
Definition at line 82 of file rich_status.hpp.
|
inlinenodiscard |
Definition at line 81 of file rich_status.hpp.
|
inlineexplicitnodiscard |
Definition at line 88 of file rich_status.hpp.
|
nodiscard |
Converts this RichStatus to a grpc::Status.
grpc::Status with serialized error details.
|
staticnodiscard |
Attempts to extract a specific rich error detail from google::rpc::Status
std::nullopt otherwiseAccording 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.
Definition at line 391 of file rich_status.hpp.