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:
David Pedersen
2021-08-07 16:44:12 +02:00
committed by GitHub
parent b5b9db47db
commit 95d7582d28
4 changed files with 46 additions and 12 deletions
+2 -2
View File
@@ -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>,