Struct tonic_types::ErrorDetails
source · #[non_exhaustive]pub struct ErrorDetails { /* private fields */ }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.
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_types::{ErrorDetails};
let err_details = ErrorDetails::new();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_types::{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_types::{ErrorDetails};
let err_details = ErrorDetails::with_bad_request_violation(
"field",
"description",
);sourcepub fn bad_request(&self) -> Option<BadRequest>
pub fn bad_request(&self) -> Option<BadRequest>
Get BadRequest details, if any
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_types::{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_types::{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_types::{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);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