pub trait MapHandlerError<T> {
    // Required method
    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§

source

fn map_err_with_status(self, status_code: StatusCode) -> Result<T, HandlerError>

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

Implementations on Foreign Types§

source§

impl<T, E> MapHandlerError<T> for Result<T, E>where E: Into<Error> + Display,

Implementors§