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 -1
View File
@@ -6,6 +6,7 @@ use crate::{
buffer::MpscBuffer,
extract::connect_info::{Connected, IntoMakeServiceWithConnectInfo},
response::IntoResponse,
service::HandleErrorFromRouter,
util::ByteStr,
};
use async_trait::async_trait;
@@ -716,7 +717,7 @@ impl<S> Layered<S> {
pub fn handle_error<F, ReqBody, ResBody, Res, E>(
self,
f: F,
) -> crate::service::HandleError<S, F, ReqBody>
) -> crate::service::HandleError<S, F, ReqBody, HandleErrorFromRouter>
where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone,
F: FnOnce(S::Error) -> Result<Res, E>,