Trait tonic_richer_error::WithErrorDetails
source · pub trait WithErrorDetails {
Show 16 methods
// Required methods
fn with_error_details(
code: Code,
message: impl Into<String>,
details: ErrorDetails
) -> Status;
fn with_error_details_vec(
code: Code,
message: impl Into<String>,
details: Vec<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.
Required Methods§
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_richer_error::{ErrorDetails, WithErrorDetails};
let status = Status::with_error_details(
Code::InvalidArgument,
"bad request",
ErrorDetails::with_bad_request_violation("field", "description"),
);
sourcefn with_error_details_vec(
code: Code,
message: impl Into<String>,
details: Vec<ErrorDetail>
) -> Status
fn with_error_details_vec( code: Code, message: impl Into<String>, details: Vec<ErrorDetail> ) -> Status
Generates a tonic::Status
with error details provided in a vector of
ErrorDetail
enums.
Examples
use tonic::{Code, Status};
use tonic_richer_error::{BadRequest, WithErrorDetails};
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
WithErrorDetails::get_error_details
or
WithErrorDetails::get_error_details_vec
.
Examples
use tonic::{Status, Response};
use tonic_richer_error::{WithErrorDetails};
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 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_richer_error::{WithErrorDetails};
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
WithErrorDetails::get_error_details_vec
or
WithErrorDetails::get_error_details
.
Examples
use tonic::{Status, Response};
use tonic_richer_error::{ErrorDetail, WithErrorDetails};
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_richer_error::{ErrorDetail, WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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_richer_error::{WithErrorDetails};
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
}
}
};
}