pub trait StatusExt: Sealed {
Show 18 methods
// Required methods
fn with_error_details_and_metadata(
code: Code,
message: impl Into<String>,
details: ErrorDetails,
metadata: MetadataMap,
) -> Status;
fn with_error_details(
code: Code,
message: impl Into<String>,
details: ErrorDetails,
) -> Status;
fn with_error_details_vec_and_metadata(
code: Code,
message: impl Into<String>,
details: impl IntoIterator<Item = ErrorDetail>,
metadata: MetadataMap,
) -> Status;
fn with_error_details_vec(
code: Code,
message: impl Into<String>,
details: impl IntoIterator<Item = ErrorDetail>,
) -> Status;
fn check_error_details(&self) -> Result<ErrorDetails, DecodeError>;
fn get_error_details(&self) -> ErrorDetails;
fn check_error_details_vec(&self) -> Result<Vec<ErrorDetail>, DecodeError>;
fn get_error_details_vec(&self) -> Vec<ErrorDetail>;
fn get_details_retry_info(&self) -> Option<RetryInfo>;
fn get_details_debug_info(&self) -> Option<DebugInfo>;
fn get_details_quota_failure(&self) -> Option<QuotaFailure>;
fn get_details_error_info(&self) -> Option<ErrorInfo>;
fn get_details_precondition_failure(&self) -> Option<PreconditionFailure>;
fn get_details_bad_request(&self) -> Option<BadRequest>;
fn get_details_request_info(&self) -> Option<RequestInfo>;
fn get_details_resource_info(&self) -> Option<ResourceInfo>;
fn get_details_help(&self) -> Option<Help>;
fn get_details_localized_message(&self) -> Option<LocalizedMessage>;
}Expand description
Used to implement associated functions and methods on tonic::Status, that
allow the addition and extraction of standard error details. This trait is
sealed and not meant to be implemented outside of tonic-types.
Required Methods§
Sourcefn with_error_details_and_metadata(
code: Code,
message: impl Into<String>,
details: ErrorDetails,
metadata: MetadataMap,
) -> Status
fn with_error_details_and_metadata( code: Code, message: impl Into<String>, details: ErrorDetails, metadata: MetadataMap, ) -> Status
Generates a tonic::Status with error details obtained from an
ErrorDetails struct, and custom metadata.
§Examples
use tonic::{metadata::MetadataMap, Code, Status};
use tonic_types::{ErrorDetails, StatusExt};
let status = Status::with_error_details_and_metadata(
Code::InvalidArgument,
"bad request",
ErrorDetails::with_bad_request_violation("field", "description"),
MetadataMap::new()
);Sourcefn with_error_details(
code: Code,
message: impl Into<String>,
details: ErrorDetails,
) -> Status
fn with_error_details( code: Code, message: impl Into<String>, details: ErrorDetails, ) -> Status
Generates a tonic::Status with error details obtained from an
ErrorDetails struct.
§Examples
use tonic::{Code, Status};
use tonic_types::{ErrorDetails, StatusExt};
let status = Status::with_error_details(
Code::InvalidArgument,
"bad request",
ErrorDetails::with_bad_request_violation("field", "description"),
);Sourcefn with_error_details_vec_and_metadata(
code: Code,
message: impl Into<String>,
details: impl IntoIterator<Item = ErrorDetail>,
metadata: MetadataMap,
) -> Status
fn with_error_details_vec_and_metadata( code: Code, message: impl Into<String>, details: impl IntoIterator<Item = ErrorDetail>, metadata: MetadataMap, ) -> Status
Generates a tonic::Status with error details provided in a vector of
ErrorDetail enums, and custom metadata.
§Examples
use tonic::{metadata::MetadataMap, Code, Status};
use tonic_types::{BadRequest, StatusExt};
let status = Status::with_error_details_vec_and_metadata(
Code::InvalidArgument,
"bad request",
vec![
BadRequest::with_violation("field", "description").into(),
],
MetadataMap::new()
);Sourcefn with_error_details_vec(
code: Code,
message: impl Into<String>,
details: impl IntoIterator<Item = ErrorDetail>,
) -> Status
fn with_error_details_vec( code: Code, message: impl Into<String>, details: impl IntoIterator<Item = ErrorDetail>, ) -> Status
Generates a tonic::Status with error details provided in a vector of
ErrorDetail enums.
§Examples
use tonic::{Code, Status};
use tonic_types::{BadRequest, StatusExt};
let status = Status::with_error_details_vec(
Code::InvalidArgument,
"bad request",
vec![
BadRequest::with_violation("field", "description").into(),
]
);Sourcefn check_error_details(&self) -> Result<ErrorDetails, DecodeError>
fn check_error_details(&self) -> Result<ErrorDetails, DecodeError>
Can be used to check if the error details contained in tonic::Status
are malformed or not. Tries to get an ErrorDetails struct from a
tonic::Status. If some prost::DecodeError occurs, it will be
returned. If not debugging, consider using
StatusExt::get_error_details or
StatusExt::get_error_details_vec.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => match status.check_error_details() {
Ok(err_details) => {
// Handle extracted details
}
Err(decode_error) => {
// Handle decode_error
}
}
};
}Sourcefn get_error_details(&self) -> ErrorDetails
fn get_error_details(&self) -> ErrorDetails
Get an ErrorDetails struct from tonic::Status. If some
prost::DecodeError occurs, an empty ErrorDetails struct will be
returned.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
let err_details = status.get_error_details();
if let Some(bad_request) = err_details.bad_request() {
// Handle bad_request details
}
// ...
}
};
}Sourcefn check_error_details_vec(&self) -> Result<Vec<ErrorDetail>, DecodeError>
fn check_error_details_vec(&self) -> Result<Vec<ErrorDetail>, DecodeError>
Can be used to check if the error details contained in tonic::Status
are malformed or not. Tries to get a vector of ErrorDetail enums
from a tonic::Status. If some prost::DecodeError occurs, it will be
returned. If not debugging, consider using
StatusExt::get_error_details_vec or
StatusExt::get_error_details.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => match status.check_error_details_vec() {
Ok(err_details) => {
// Handle extracted details
}
Err(decode_error) => {
// Handle decode_error
}
}
};
}Sourcefn get_error_details_vec(&self) -> Vec<ErrorDetail>
fn get_error_details_vec(&self) -> Vec<ErrorDetail>
Get a vector of ErrorDetail enums from tonic::Status. If some
prost::DecodeError occurs, an empty vector will be returned.
§Examples
use tonic::{Status, Response};
use tonic_types::{ErrorDetail, StatusExt};
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
let err_details = status.get_error_details_vec();
for err_detail in err_details.iter() {
match err_detail {
ErrorDetail::BadRequest(bad_request) => {
// Handle bad_request details
}
// ...
_ => {}
}
}
}
};
}Sourcefn get_details_retry_info(&self) -> Option<RetryInfo>
fn get_details_retry_info(&self) -> Option<RetryInfo>
Get first RetryInfo details found on tonic::Status, if any. If
some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(retry_info) = status.get_details_retry_info() {
// Handle retry_info details
}
}
};
}Sourcefn get_details_debug_info(&self) -> Option<DebugInfo>
fn get_details_debug_info(&self) -> Option<DebugInfo>
Get first DebugInfo details found on tonic::Status, if any. If
some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(debug_info) = status.get_details_debug_info() {
// Handle debug_info details
}
}
};
}Sourcefn get_details_quota_failure(&self) -> Option<QuotaFailure>
fn get_details_quota_failure(&self) -> Option<QuotaFailure>
Get first QuotaFailure details found on tonic::Status, if any.
If some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(quota_failure) = status.get_details_quota_failure() {
// Handle quota_failure details
}
}
};
}Sourcefn get_details_error_info(&self) -> Option<ErrorInfo>
fn get_details_error_info(&self) -> Option<ErrorInfo>
Get first ErrorInfo details found on tonic::Status, if any. If
some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(error_info) = status.get_details_error_info() {
// Handle error_info details
}
}
};
}Sourcefn get_details_precondition_failure(&self) -> Option<PreconditionFailure>
fn get_details_precondition_failure(&self) -> Option<PreconditionFailure>
Get first PreconditionFailure details found on tonic::Status,
if any. If some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(precondition_failure) = status.get_details_precondition_failure() {
// Handle precondition_failure details
}
}
};
}Sourcefn get_details_bad_request(&self) -> Option<BadRequest>
fn get_details_bad_request(&self) -> Option<BadRequest>
Get first BadRequest details found on tonic::Status, if any. If
some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(bad_request) = status.get_details_bad_request() {
// Handle bad_request details
}
}
};
}Sourcefn get_details_request_info(&self) -> Option<RequestInfo>
fn get_details_request_info(&self) -> Option<RequestInfo>
Get first RequestInfo details found on tonic::Status, if any.
If some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(request_info) = status.get_details_request_info() {
// Handle request_info details
}
}
};
}Sourcefn get_details_resource_info(&self) -> Option<ResourceInfo>
fn get_details_resource_info(&self) -> Option<ResourceInfo>
Get first ResourceInfo details found on tonic::Status, if any.
If some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(resource_info) = status.get_details_resource_info() {
// Handle resource_info details
}
}
};
}Sourcefn get_details_help(&self) -> Option<Help>
fn get_details_help(&self) -> Option<Help>
Get first Help details found on tonic::Status, if any. If some
prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(help) = status.get_details_help() {
// Handle help details
}
}
};
}Sourcefn get_details_localized_message(&self) -> Option<LocalizedMessage>
fn get_details_localized_message(&self) -> Option<LocalizedMessage>
Get first LocalizedMessage details found on tonic::Status, if
any. If some prost::DecodeError occurs, returns None.
§Examples
use tonic::{Status, Response};
use tonic_types::StatusExt;
fn handle_request_result<T>(req_result: Result<Response<T>, Status>) {
match req_result {
Ok(_) => {},
Err(status) => {
if let Some(localized_message) = status.get_details_localized_message() {
// Handle localized_message details
}
}
};
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.