[][src]Trait gotham::handler::MapHandlerError

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

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

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

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

Loading content...

Implementations on Foreign Types

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

Loading content...

Implementors

Loading content...