mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-24 00:00:16 +02:00
More error handling of layered handlers
This commit is contained in:
+15
-2
@@ -1,5 +1,6 @@
|
||||
use crate::{body::Body, extract::FromRequest, response::IntoResponse};
|
||||
use crate::{body::Body, HandleError, extract::FromRequest, response::IntoResponse};
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use futures_util::future;
|
||||
use http::{Request, Response};
|
||||
use std::{
|
||||
@@ -8,7 +9,7 @@ use std::{
|
||||
marker::PhantomData,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tower::{Layer, Service, ServiceExt};
|
||||
use tower::{Layer, BoxError, Service, ServiceExt};
|
||||
|
||||
mod sealed {
|
||||
pub trait HiddentTrait {}
|
||||
@@ -141,6 +142,18 @@ impl<S, T> Layered<S, T> {
|
||||
_input: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_error<F, B, Res>(self, f: F) -> Layered<HandleError<S, F, S::Error>, T>
|
||||
where
|
||||
S: Service<Request<Body>, Response = Response<B>>,
|
||||
F: FnOnce(S::Error) -> Res,
|
||||
Res: IntoResponse<Body>,
|
||||
B: http_body::Body<Data = Bytes> + Send + Sync + 'static,
|
||||
B::Error: Into<BoxError> + Send + Sync + 'static,
|
||||
{
|
||||
let svc = HandleError::new(self.svc, f);
|
||||
Layered::new(svc)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HandlerSvc<H, B, T> {
|
||||
|
||||
Reference in New Issue
Block a user