Handling errors from middleware from_fn #1151
-
Hi! I've got a a middleware that I'm using to protect a route from being accessed if the user making the request isn't authorized. I'm new to rust, so I'm using the
I tried this:
but get the following compiler error and I'm not quite sure what to do
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, though I perfer
I think you're misunderstanding how axum thinks about errors. Returning I recommend you just log error directly in Specifically for timeouts I recommend https://docs.rs/tower-http/latest/tower_http/timeout/index.html as it doesn't require |
Beta Was this translation helpful? Give feedback.
Yes, though I perfer
.route("/calculate", post(...).layer(...))
. I think thats more clear but it ultimately doesn't matter.I think you're misunderstanding how axum thinks about errors. Returning
500 Internal Server
(or some other status) from a handler is not an error. Thats just another response. Errors only occur when you apply fallible middleware likeTimeoutLayer
. Notice that it's error type isn'tInfallible
which axum requires.I recommend you just log error directly in
routes::pr…