Struct http_types::Error
source · pub struct Error { /* private fields */ }
Expand description
The error type for HTTP operations.
Implementations§
source§impl Error
impl Error
sourcepub fn new<S, E>(status: S, error: E) -> Selfwhere
S: TryInto<StatusCode>,
S::Error: Debug,
E: Into<Error>,
pub fn new<S, E>(status: S, error: E) -> Selfwhere S: TryInto<StatusCode>, S::Error: Debug, E: Into<Error>,
Create a new error object from any error type.
The error type must be threadsafe and ’static, so that the Error will be as well. If the error type does not provide a backtrace, a backtrace will be created here to ensure that a backtrace exists.
sourcepub fn from_str<S, M>(status: S, msg: M) -> Selfwhere
S: TryInto<StatusCode>,
S::Error: Debug,
M: Display + Debug + Send + Sync + 'static,
pub fn from_str<S, M>(status: S, msg: M) -> Selfwhere S: TryInto<StatusCode>, S::Error: Debug, M: Display + Debug + Send + Sync + 'static,
Create a new error object from static string.
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the status code associated with this error.
sourcepub fn set_status<S>(&mut self, status: S)where
S: TryInto<StatusCode>,
S::Error: Debug,
pub fn set_status<S>(&mut self, status: S)where S: TryInto<StatusCode>, S::Error: Debug,
Set the status code associated with this error.
pub const fn backtrace(&self) -> Option<BacktracePlaceholder>
sourcepub fn into_inner(self) -> Error
pub fn into_inner(self) -> Error
Returns the inner anyhow::Error
Note: This will lose status code information
sourcepub fn downcast<E>(self) -> Result<E, Self>where
E: Display + Debug + Send + Sync + 'static,
pub fn downcast<E>(self) -> Result<E, Self>where E: Display + Debug + Send + Sync + 'static,
Attempt to downcast the error object to a concrete type.
sourcepub fn downcast_ref<E>(&self) -> Option<&E>where
E: Display + Debug + Send + Sync + 'static,
pub fn downcast_ref<E>(&self) -> Option<&E>where E: Display + Debug + Send + Sync + 'static,
Downcast this error object by reference.
sourcepub fn downcast_mut<E>(&mut self) -> Option<&mut E>where
E: Display + Debug + Send + Sync + 'static,
pub fn downcast_mut<E>(&mut self) -> Option<&mut E>where E: Display + Debug + Send + Sync + 'static,
Downcast this error object by mutable reference.
sourcepub fn type_name(&self) -> Option<&str>
pub fn type_name(&self) -> Option<&str>
Retrieves a reference to the type name of the error, if available.
sourcepub fn from_display<D: Display>(error: D) -> Self
pub fn from_display<D: Display>(error: D) -> Self
Converts anything which implements Display
into an http_types::Error
.
This is handy for errors which are not Send + Sync + 'static
because std::error::Error
requires Display
.
Note that any assiciated context not included in the Display
output will be lost,
and so this may be lossy for some types which implement std::error::Error
.
Note: Prefer error.into()
via From<Into<anyhow::Error>>
when possible!
sourcepub fn from_debug<D: Debug>(error: D) -> Self
pub fn from_debug<D: Debug>(error: D) -> Self
Converts anything which implements Debug
into an http_types::Error
.
This is handy for errors which are not Send + Sync + 'static
because std::error::Error
requires Debug
.
Note that any assiciated context not included in the Debug
output will be lost,
and so this may be lossy for some types which implement std::error::Error
.
Note: Prefer error.into()
via From<Into<anyhow::Error>>
when possible!