mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-20 00:00:11 +02:00
Fix ServiceExt::handle_error footgun (#120)
As described in https://github.com/tokio-rs/axum/pull/108#issuecomment-892811637, a `HandleError` created from `axum::ServiceExt::handle_error` should _not_ implement `RoutingDsl` as that leads to confusing routing behavior. The technique used here of adding another type parameter to `HandleError` isn't very clean, I think. But the alternative is duplicating `HandleError` and having two versions, which I think is less desirable.
This commit is contained in:
+2
-2
@@ -5,7 +5,7 @@ use crate::{
|
||||
extract::FromRequest,
|
||||
response::IntoResponse,
|
||||
routing::{future::RouteFuture, EmptyRouter, MethodFilter},
|
||||
service::HandleError,
|
||||
service::{HandleError, HandleErrorFromRouter},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
@@ -371,7 +371,7 @@ impl<S, T> Layered<S, T> {
|
||||
pub fn handle_error<F, ReqBody, ResBody, Res, E>(
|
||||
self,
|
||||
f: F,
|
||||
) -> Layered<HandleError<S, F, ReqBody>, T>
|
||||
) -> Layered<HandleError<S, F, ReqBody, HandleErrorFromRouter>, T>
|
||||
where
|
||||
S: Service<Request<ReqBody>, Response = Response<ResBody>>,
|
||||
F: FnOnce(S::Error) -> Result<Res, E>,
|
||||
|
||||
Reference in New Issue
Block a user