axum_prehandle/prefabs/
map_error.rs1use std::marker::PhantomData;
2
3use async_trait::async_trait;
4use axum::extract::RequestParts;
5
6use crate::PreHandler;
7
8pub struct MapError<B: Send, H: PreHandler<B>, R: From<H::Rejection>>(PhantomData<(B, H, R)>);
9
10#[async_trait]
11impl<B, H, R> PreHandler<B> for MapError<B, H, R>
12where
13 B: Send,
14 H: PreHandler<B>,
15 R: From<H::Rejection>,
16{
17 type Output = H::Output;
18
19 type Rejection = R;
20
21 async fn handling(request: &mut RequestParts<B>) -> Result<Self::Output, Self::Rejection> {
22 H::handling(request).await.map_err(R::from)
23 }
24}