pub struct HandlerError { /* private fields */ }
Expand description

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

Implementations

Returns the HTTP status code associated with this HandlerError.

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);

Returns the cause of this error by reference.

Returns the cause of this error.

Attempt to downcast the cause by reference.

Attempt to downcast the cause by mutable reference.

Trait Implementations

Formats the value using the given formatter. Read more

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

Converts to this type from the input type.

Converts this value into a hyper::Response

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more