Struct anyhow_http::HttpError
source · pub struct HttpError<R> {
pub status_code: StatusCode,
pub reason: Option<String>,
pub source: Option<Error>,
pub data: HashMap<String, Value>,
/* private fields */
}Expand description
HttpError is an error that can be represented as a HTTP response. HttpError is generic over
its response format, allowing consumers to implement their custom error response. See IntoHttpErrorResponse.
Fields§
§status_code: StatusCode§reason: Option<String>§source: Option<Error>§data: HashMap<String, Value>Implementations§
source§impl<R> HttpError<R>where
R: Debug + Sync + Send + 'static,
impl<R> HttpError<R>where R: Debug + Sync + Send + 'static,
sourcepub fn from_status_code(status_code: StatusCode) -> Self
pub fn from_status_code(status_code: StatusCode) -> Self
Creates a HttpError from a status code.
sourcepub fn from_http_err<S>(http_err: HttpError<S>) -> Self
pub fn from_http_err<S>(http_err: HttpError<S>) -> Self
sourcepub fn with_status_code(self, status_code: StatusCode) -> Self
pub fn with_status_code(self, status_code: StatusCode) -> Self
Sets the status code.
sourcepub fn with_reason<S: ToString>(self, reason: S) -> Self
pub fn with_reason<S: ToString>(self, reason: S) -> Self
Sets the error reason.
sourcepub fn with_dyn_source_err(
self,
err: Box<dyn Error + Send + Sync + 'static>
) -> Self
pub fn with_dyn_source_err( self, err: Box<dyn Error + Send + Sync + 'static> ) -> Self
Set the source error from a generic error trait object.
sourcepub fn with_source_err<E>(self, err: E) -> Selfwhere
E: Into<Error>,
pub fn with_source_err<E>(self, err: E) -> Selfwhere E: Into<Error>,
Set the source error from a generic error.
source§impl<R> HttpError<R>where
R: IntoHttpErrorResponse<Fmt = R> + Debug + Send + Sync + 'static,
impl<R> HttpError<R>where R: IntoHttpErrorResponse<Fmt = R> + Debug + Send + Sync + 'static,
sourcepub fn into_http_error_response(self) -> HttpErrorResponse<R>
pub fn into_http_error_response(self) -> HttpErrorResponse<R>
Creates an error response. See IntoHttpErrorResponse.
Trait Implementations§
Auto Trait Implementations§
impl<R> RefUnwindSafe for HttpError<R>where R: RefUnwindSafe,
impl<R> Send for HttpError<R>where R: Send,
impl<R> Sync for HttpError<R>where R: Sync,
impl<R> Unpin for HttpError<R>where R: Unpin,
impl<R> UnwindSafe for HttpError<R>where R: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more