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,

source

pub fn from_status_code(status_code: StatusCode) -> Self

Creates a HttpError from a status code.

source

pub fn from_http_err<S>(http_err: HttpError<S>) -> Self

Creates a HttpError from another HttpError. This is mostly used to convert between HttpErrors with different response formats.

source

pub fn from_err<E>(err: E) -> Selfwhere E: Into<Error>,

Creates a HttpError from a generic error. It attempts to downcast to an underlying HttpError.

source

pub fn with_status_code(self, status_code: StatusCode) -> Self

Sets the status code.

source

pub fn with_reason<S: ToString>(self, reason: S) -> Self

Sets the error reason.

source

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.

source

pub fn with_source_err<E>(self, err: E) -> Selfwhere E: Into<Error>,

Set the source error from a generic error.

source

pub fn add<V>(&mut self, key: impl Into<String>, value: V) -> Result<()>where V: Serialize + Send + Sync,

Adds a key-pair value to the inner data.

source

pub fn get<V>(&self, key: impl AsRef<str>) -> Option<V>where V: DeserializeOwned + Send + Sync,

Retrieves a key-pair value from the inner data.

source§

impl<R> HttpError<R>where R: IntoHttpErrorResponse<Fmt = R> + Debug + Send + Sync + 'static,

source

pub fn into_http_error_response(self) -> HttpErrorResponse<R>

Creates an error response. See IntoHttpErrorResponse.

Trait Implementations§

source§

impl<R: Debug> Debug for HttpError<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<R> Default for HttpError<R>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<R> Display for HttpError<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<E, R> From<E> for HttpError<R>where E: Into<Error>, R: Debug + Sync + Send + 'static,

source§

fn from(err: E) -> Self

Converts to this type from the input type.

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.