Struct gotham::handler::HandlerError
source · [−]pub struct HandlerError { /* private fields */ }
Expand description
Describes an error which occurred during handler execution, and allows the creation of a HTTP
Response
.
Implementations
sourceimpl HandlerError
impl HandlerError
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the HTTP status code associated with this HandlerError
.
sourcepub fn with_status(self, status_code: StatusCode) -> HandlerError
pub fn with_status(self, status_code: StatusCode) -> 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);
Trait Implementations
sourceimpl Debug for HandlerError
impl Debug for HandlerError
sourceimpl<E> From<E> for HandlerError where
E: Into<Error> + Display,
impl<E> From<E> for HandlerError where
E: Into<Error> + Display,
Convert a generic anyhow::Error
into a HandlerError
, similar as you would a concrete error
type with into_handler_error()
.
sourcefn from(error: E) -> HandlerError
fn from(error: E) -> HandlerError
Performs the conversion.
sourceimpl IntoResponse for HandlerError
impl IntoResponse for HandlerError
sourcefn into_response(self, state: &State) -> Response<Body>
fn into_response(self, state: &State) -> Response<Body>
Converts this value into a hyper::Response
Auto Trait Implementations
impl RefUnwindSafe for HandlerError
impl Send for HandlerError
impl Sync for HandlerError
impl Unpin for HandlerError
impl UnwindSafe for HandlerError
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more