Struct tonic_richer_error::ErrorDetails
source · pub struct ErrorDetails {
pub retry_info: Option<RetryInfo>,
pub debug_info: Option<DebugInfo>,
pub quota_failure: Option<QuotaFailure>,
pub error_info: Option<ErrorInfo>,
pub precondition_failure: Option<PreconditionFailure>,
pub bad_request: Option<BadRequest>,
pub request_info: Option<RequestInfo>,
pub resource_info: Option<ResourceInfo>,
pub help: Option<Help>,
pub localized_message: Option<LocalizedMessage>,
}
Expand description
Groups the standard error messages structs. Provides associated
functions and methods to setup and edit each error message independently.
Used when extracting error details from tonic::Status
, and when
creating a tonic::Status
with error details.
Fields§
§retry_info: Option<RetryInfo>
This field stores RetryInfo
data, if any.
debug_info: Option<DebugInfo>
This field stores DebugInfo
data, if any.
quota_failure: Option<QuotaFailure>
This field stores QuotaFailure
data, if any.
error_info: Option<ErrorInfo>
This field stores ErrorInfo
data, if any.
precondition_failure: Option<PreconditionFailure>
This field stores PreconditionFailure
data, if any.
bad_request: Option<BadRequest>
This field stores BadRequest
data, if any.
request_info: Option<RequestInfo>
This field stores RequestInfo
data, if any.
resource_info: Option<ResourceInfo>
This field stores ResourceInfo
data, if any.
help: Option<Help>
This field stores Help
data, if any.
localized_message: Option<LocalizedMessage>
This field stores LocalizedMessage
data, if any.
Implementations§
source§impl ErrorDetails
impl ErrorDetails
sourcepub fn new() -> Self
pub fn new() -> Self
Generates an ErrorDetails
struct with all fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::new();
sourcepub fn with_retry_info(retry_delay: Option<Duration>) -> Self
pub fn with_retry_info(retry_delay: Option<Duration>) -> Self
Generates an ErrorDetails
struct with RetryInfo
details and
remaining fields set to None
.
Examples
use std::time::Duration;
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_retry_info(Some(Duration::from_secs(5)));
sourcepub fn with_debug_info(
stack_entries: Vec<String>,
detail: impl Into<String>
) -> Self
pub fn with_debug_info( stack_entries: Vec<String>, detail: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with DebugInfo
details and
remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_stack = vec!["...".into(), "...".into()];
let err_details = ErrorDetails::with_debug_info(err_stack, "error details");
sourcepub fn with_quota_failure(violations: Vec<QuotaViolation>) -> Self
pub fn with_quota_failure(violations: Vec<QuotaViolation>) -> Self
Generates an ErrorDetails
struct with QuotaFailure
details and
remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails, QuotaViolation};
let err_details = ErrorDetails::with_quota_failure(vec![
QuotaViolation::new("subject 1", "description 1"),
QuotaViolation::new("subject 2", "description 2"),
]);
sourcepub fn with_quota_failure_violation(
subject: impl Into<String>,
description: impl Into<String>
) -> Self
pub fn with_quota_failure_violation( subject: impl Into<String>, description: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with QuotaFailure
details (one
QuotaViolation
set) and remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_quota_failure_violation("subject", "description");
sourcepub fn with_error_info(
reason: impl Into<String>,
domain: impl Into<String>,
metadata: HashMap<String, String>
) -> Self
pub fn with_error_info( reason: impl Into<String>, domain: impl Into<String>, metadata: HashMap<String, String> ) -> Self
Generates an ErrorDetails
struct with ErrorInfo
details and
remaining fields set to None
.
Examples
use std::collections::HashMap;
use tonic_richer_error::{ErrorDetails};
let mut metadata: HashMap<String, String> = HashMap::new();
metadata.insert("instanceLimitPerRequest".into(), "100".into());
let err_details = ErrorDetails::with_error_info("reason", "domain", metadata);
sourcepub fn with_precondition_failure(violations: Vec<PreconditionViolation>) -> Self
pub fn with_precondition_failure(violations: Vec<PreconditionViolation>) -> Self
Generates an ErrorDetails
struct with PreconditionFailure
details and remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails, PreconditionViolation};
let err_details = ErrorDetails::with_precondition_failure(vec![
PreconditionViolation::new(
"violation type 1",
"subject 1",
"description 1",
),
PreconditionViolation::new(
"violation type 2",
"subject 2",
"description 2",
),
]);
sourcepub fn with_precondition_failure_violation(
violation_type: impl Into<String>,
subject: impl Into<String>,
description: impl Into<String>
) -> Self
pub fn with_precondition_failure_violation( violation_type: impl Into<String>, subject: impl Into<String>, description: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with PreconditionFailure
details (one PreconditionViolation
set) and remaining fields set to
None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_precondition_failure_violation(
"violation type",
"subject",
"description",
);
sourcepub fn with_bad_request(field_violations: Vec<FieldViolation>) -> Self
pub fn with_bad_request(field_violations: Vec<FieldViolation>) -> Self
Generates an ErrorDetails
struct with BadRequest
details and
remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails, FieldViolation};
let err_details = ErrorDetails::with_bad_request(vec![
FieldViolation::new("field_1", "description 1"),
FieldViolation::new("field_2", "description 2"),
]);
sourcepub fn with_bad_request_violation(
field: impl Into<String>,
description: impl Into<String>
) -> Self
pub fn with_bad_request_violation( field: impl Into<String>, description: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with BadRequest
details (one
FieldViolation
set) and remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_bad_request_violation(
"field",
"description",
);
sourcepub fn with_request_info(
request_id: impl Into<String>,
serving_data: impl Into<String>
) -> Self
pub fn with_request_info( request_id: impl Into<String>, serving_data: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with RequestInfo
details and
remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_request_info(
"request_id",
"serving_data",
);
sourcepub fn with_resource_info(
resource_type: impl Into<String>,
resource_name: impl Into<String>,
owner: impl Into<String>,
description: impl Into<String>
) -> Self
pub fn with_resource_info( resource_type: impl Into<String>, resource_name: impl Into<String>, owner: impl Into<String>, description: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with ResourceInfo
details and
remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_resource_info(
"res_type",
"res_name",
"owner",
"description",
);
sourcepub fn with_help(links: Vec<HelpLink>) -> Self
pub fn with_help(links: Vec<HelpLink>) -> Self
Generates an ErrorDetails
struct with Help
details and
remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails, HelpLink};
let err_details = ErrorDetails::with_help(vec![
HelpLink::new("description of link a", "resource-a.example.local"),
HelpLink::new("description of link b", "resource-b.example.local"),
]);
sourcepub fn with_help_link(
description: impl Into<String>,
url: impl Into<String>
) -> Self
pub fn with_help_link( description: impl Into<String>, url: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with Help
details (one
HelpLink
set) and remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_help_link(
"description of link a",
"resource-a.example.local"
);
sourcepub fn with_localized_message(
locale: impl Into<String>,
message: impl Into<String>
) -> Self
pub fn with_localized_message( locale: impl Into<String>, message: impl Into<String> ) -> Self
Generates an ErrorDetails
struct with LocalizedMessage
details
and remaining fields set to None
.
Examples
use tonic_richer_error::{ErrorDetails};
let err_details = ErrorDetails::with_localized_message(
"en-US",
"message for the user"
);
source§impl ErrorDetails
impl ErrorDetails
sourcepub fn set_retry_info(&mut self, retry_delay: Option<Duration>) -> &mut Self
pub fn set_retry_info(&mut self, retry_delay: Option<Duration>) -> &mut Self
Set RetryInfo
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use std::time::Duration;
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.set_retry_info(Some(Duration::from_secs(5)));
sourcepub fn set_debug_info(
&mut self,
stack_entries: Vec<String>,
detail: impl Into<String>
) -> &mut Self
pub fn set_debug_info( &mut self, stack_entries: Vec<String>, detail: impl Into<String> ) -> &mut Self
Set DebugInfo
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
let err_stack = vec!["...".into(), "...".into()];
err_details.set_debug_info(err_stack, "error details");
sourcepub fn set_quota_failure(
&mut self,
violations: Vec<QuotaViolation>
) -> &mut Self
pub fn set_quota_failure( &mut self, violations: Vec<QuotaViolation> ) -> &mut Self
Set QuotaFailure
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails, QuotaViolation};
let mut err_details = ErrorDetails::new();
err_details.set_quota_failure(vec![
QuotaViolation::new("subject 1", "description 1"),
QuotaViolation::new("subject 2", "description 2"),
]);
sourcepub fn add_quota_failure_violation(
&mut self,
subject: impl Into<String>,
description: impl Into<String>
) -> &mut Self
pub fn add_quota_failure_violation( &mut self, subject: impl Into<String>, description: impl Into<String> ) -> &mut Self
Adds a QuotaViolation
to QuotaFailure
details. Sets
QuotaFailure
details if it is not set yet. Can be chained with
other .set_
and .add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.add_quota_failure_violation("subject", "description");
sourcepub fn has_quota_failure_violations(&self) -> bool
pub fn has_quota_failure_violations(&self) -> bool
Returns true
if QuotaFailure
is set and its violations
vector
is not empty, otherwise returns false
.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::with_quota_failure(vec![]);
assert_eq!(err_details.has_quota_failure_violations(), false);
err_details.add_quota_failure_violation("subject", "description");
assert_eq!(err_details.has_quota_failure_violations(), true);
sourcepub fn set_error_info(
&mut self,
reason: impl Into<String>,
domain: impl Into<String>,
metadata: HashMap<String, String>
) -> &mut Self
pub fn set_error_info( &mut self, reason: impl Into<String>, domain: impl Into<String>, metadata: HashMap<String, String> ) -> &mut Self
Set ErrorInfo
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use std::collections::HashMap;
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
let mut metadata: HashMap<String, String> = HashMap::new();
metadata.insert("instanceLimitPerRequest".into(), "100".into());
err_details.set_error_info("reason", "example.local", metadata);
sourcepub fn set_precondition_failure(
&mut self,
violations: Vec<PreconditionViolation>
) -> &mut Self
pub fn set_precondition_failure( &mut self, violations: Vec<PreconditionViolation> ) -> &mut Self
Set PreconditionFailure
details. Can be chained with other .set_
and .add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails, PreconditionViolation};
let mut err_details = ErrorDetails::new();
err_details.set_precondition_failure(vec![
PreconditionViolation::new(
"violation type 1",
"subject 1",
"description 1",
),
PreconditionViolation::new(
"violation type 2",
"subject 2",
"description 2",
),
]);
sourcepub fn add_precondition_failure_violation(
&mut self,
violation_type: impl Into<String>,
subject: impl Into<String>,
description: impl Into<String>
) -> &mut Self
pub fn add_precondition_failure_violation( &mut self, violation_type: impl Into<String>, subject: impl Into<String>, description: impl Into<String> ) -> &mut Self
Adds a PreconditionViolation
to PreconditionFailure
details.
Sets PreconditionFailure
details if it is not set yet. Can be
chained with other .set_
and .add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.add_precondition_failure_violation(
"violation type",
"subject",
"description"
);
sourcepub fn has_precondition_failure_violations(&self) -> bool
pub fn has_precondition_failure_violations(&self) -> bool
Returns true
if PreconditionFailure
is set and its violations
vector is not empty, otherwise returns false
.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::with_precondition_failure(vec![]);
assert_eq!(err_details.has_precondition_failure_violations(), false);
err_details.add_precondition_failure_violation(
"violation type",
"subject",
"description"
);
assert_eq!(err_details.has_precondition_failure_violations(), true);
sourcepub fn set_bad_request(&mut self, violations: Vec<FieldViolation>) -> &mut Self
pub fn set_bad_request(&mut self, violations: Vec<FieldViolation>) -> &mut Self
Set BadRequest
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails, FieldViolation};
let mut err_details = ErrorDetails::new();
err_details.set_bad_request(vec![
FieldViolation::new("field_1", "description 1"),
FieldViolation::new("field_2", "description 2"),
]);
sourcepub fn add_bad_request_violation(
&mut self,
field: impl Into<String>,
description: impl Into<String>
) -> &mut Self
pub fn add_bad_request_violation( &mut self, field: impl Into<String>, description: impl Into<String> ) -> &mut Self
Adds a FieldViolation
to BadRequest
details. Sets
BadRequest
details if it is not set yet. Can be chained with other
.set_
and .add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.add_bad_request_violation("field", "description");
sourcepub fn has_bad_request_violations(&self) -> bool
pub fn has_bad_request_violations(&self) -> bool
Returns true
if BadRequest
is set and its field_violations
vector is not empty, otherwise returns false
.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::with_bad_request(vec![]);
assert_eq!(err_details.has_bad_request_violations(), false);
err_details.add_bad_request_violation("field", "description");
assert_eq!(err_details.has_bad_request_violations(), true);
sourcepub fn set_request_info(
&mut self,
request_id: impl Into<String>,
serving_data: impl Into<String>
) -> &mut Self
pub fn set_request_info( &mut self, request_id: impl Into<String>, serving_data: impl Into<String> ) -> &mut Self
Set RequestInfo
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.set_request_info("request_id", "serving_data");
sourcepub fn set_resource_info(
&mut self,
resource_type: impl Into<String>,
resource_name: impl Into<String>,
owner: impl Into<String>,
description: impl Into<String>
) -> &mut Self
pub fn set_resource_info( &mut self, resource_type: impl Into<String>, resource_name: impl Into<String>, owner: impl Into<String>, description: impl Into<String> ) -> &mut Self
Set ResourceInfo
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.set_resource_info("res_type", "res_name", "owner", "description");
sourcepub fn set_help(&mut self, links: Vec<HelpLink>) -> &mut Self
pub fn set_help(&mut self, links: Vec<HelpLink>) -> &mut Self
Set Help
details. Can be chained with other .set_
and .add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails, HelpLink};
let mut err_details = ErrorDetails::new();
err_details.set_help(vec![
HelpLink::new("description of link a", "resource-a.example.local"),
HelpLink::new("description of link b", "resource-b.example.local"),
]);
sourcepub fn add_help_link(
&mut self,
description: impl Into<String>,
url: impl Into<String>
) -> &mut Self
pub fn add_help_link( &mut self, description: impl Into<String>, url: impl Into<String> ) -> &mut Self
Adds a HelpLink
to Help
details. Sets Help
details if it is
not set yet. Can be chained with other .set_
and .add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.add_help_link("description of link", "resource.example.local");
sourcepub fn has_help_links(&self) -> bool
pub fn has_help_links(&self) -> bool
Returns true
if Help
is set and its links
vector is not empty,
otherwise returns false
.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::with_help(vec![]);
assert_eq!(err_details.has_help_links(), false);
err_details.add_help_link("description of link", "resource.example.local");
assert_eq!(err_details.has_help_links(), true);
sourcepub fn set_localized_message(
&mut self,
locale: impl Into<String>,
message: impl Into<String>
) -> &mut Self
pub fn set_localized_message( &mut self, locale: impl Into<String>, message: impl Into<String> ) -> &mut Self
Set LocalizedMessage
details. Can be chained with other .set_
and
.add_
ErrorDetails
methods.
Examples
use tonic_richer_error::{ErrorDetails};
let mut err_details = ErrorDetails::new();
err_details.set_localized_message("en-US", "message for the user");
Trait Implementations§
source§impl Clone for ErrorDetails
impl Clone for ErrorDetails
source§fn clone(&self) -> ErrorDetails
fn clone(&self) -> ErrorDetails
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl RefUnwindSafe for ErrorDetails
impl Send for ErrorDetails
impl Sync for ErrorDetails
impl Unpin for ErrorDetails
impl UnwindSafe for ErrorDetails
Blanket Implementations§
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request