Axum route can not add layer of tower #1636
-
create layer of tower:
and then axum route add this layer:
report an issue like the below: error[E0277]: the trait bound |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
This comment has been hidden.
This comment has been hidden.
-
Are you the same person that asked in Discord? It looks like you are using the Timeout middleware from tower, which has an Error type of Box<dyn Error + ...>. Axum requires your middlewares to have an Error type of Infallible, because usually an error at the tower service level is not what you want (here a timeout would immediately close the client connection, instead of sending a timeout HTTP response). You can either use axum's |
Beta Was this translation helpful? Give feedback.
Are you the same person that asked in Discord?
It looks like you are using the Timeout middleware from tower, which has an Error type of Box<dyn Error + ...>. Axum requires your middlewares to have an Error type of Infallible, because usually an error at the tower service level is not what you want (here a timeout would immediately close the client connection, instead of sending a timeout HTTP response).
You can either use axum's
HandleErrorLayer
to map the error into a response, or tower-http's timeout middleware https://docs.rs/tower-http/latest/tower_http/timeout/index.html as they don't change the service error type.