Struct gotham::handler::HandlerError[][src]

pub struct HandlerError { /* fields omitted */ }

Describes an error which occurred during handler execution, and allows the creation of a HTTP Response.

Implementations

impl HandlerError[src]

pub fn status(&self) -> StatusCode[src]

Returns the HTTP status code associated with this HandlerError.

pub fn with_status(self, status_code: StatusCode) -> HandlerError[src]

Sets the HTTP status code of the response which is generated by the IntoResponse implementation.

fn handler(state: State) -> Pin<Box<HandlerFuture>> {
    // It's OK if this is bogus, we just need something to convert into a `HandlerError`.
    let io_error = std::io::Error::last_os_error();

    let handler_error = HandlerError::from(io_error)
        .with_status(StatusCode::IM_A_TEAPOT);

    future::err((state, handler_error)).boxed()
}

let test_server = TestServer::new(|| Ok(handler)).unwrap();
let response = test_server.client().get("http://example.com/").perform().unwrap();
assert_eq!(response.status(), StatusCode::IM_A_TEAPOT);

pub fn downcast_cause_ref<E>(&self) -> Option<&E> where
    E: Display + Debug + Send + Sync + 'static, 
[src]

Attempt to downcast the cause by reference.

pub fn downcast_cause_mut<E>(&mut self) -> Option<&mut E> where
    E: Display + Debug + Send + Sync + 'static, 
[src]

Attempt to downcast the cause by mutable reference.

Trait Implementations

impl Debug for HandlerError[src]

impl<E> From<E> for HandlerError where
    E: Into<Error> + Display
[src]

Convert a generic anyhow::Error into a HandlerError, similar as you would a concrete error type with into_handler_error().

impl IntoResponse for HandlerError[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,