Trait gotham::prelude::MapHandlerError[][src]

pub trait MapHandlerError<T> {
    fn map_err_with_status(
        self,
        status_code: StatusCode
    ) -> Result<T, HandlerError>; }
Expand description

This trait allows you to convert a Result’s Err case into a handler error with the given status code. This is handy if you want to specify the status code but still use the ? shorthand.

fn handler() -> Result<(), HandlerError> {
    let result = Err(anyhow!("just a test"));
    result.map_err_with_status(StatusCode::IM_A_TEAPOT)?;
    unreachable!()
}

let response = handler();
assert_eq!(
    response.map_err(|err| err.status()),
    Err(StatusCode::IM_A_TEAPOT)
);

Required methods

Equivalent of map_err(|err| HandlerError::from(err).with_status(status_code)).

Implementations on Foreign Types

Implementors