Trait gotham::handler::MapHandlerErrorFuture
source · [−]pub trait MapHandlerErrorFuture {
fn map_err_with_status(
self,
status_code: StatusCode
) -> MapErrWithStatus<Self>
where
Self: Sized;
}
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() -> impl Future<Output = Result<(), HandlerError>> {
let result = async { Err(anyhow!("just a test")) };
result.map_err_with_status(StatusCode::IM_A_TEAPOT)
}
let response = block_on(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) -> MapErrWithStatus<Self> where
Self: Sized,
fn map_err_with_status(self, status_code: StatusCode) -> MapErrWithStatus<Self> where
Self: Sized,
Equivalent of map_err(|err| HandlerError::from(err).with_status(status_code))
.