You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When path extraction fails, I want to send an empty 404 response with no error message. The default error message exposes implementation details of my application to clients, and axum normally sends status code 400 instead of 404 in this situation.
With ordinary extractors like Path, this is simple: take an Option<Path<_>> or Result<Path<_>, PathRejection> instead of simply Path<_>, and then handle the failure as needed. But this is not allowed when using TypedPath because Option and Result don't implement it:
error[E0277]: the trait bound `std::option::Option<MyTypedPathStruct>: TypedPath` is not satisfied
--> src/main.rs:87:5
|
87 | .typed_get(my_handler_fn)
| ^^^^^^^^^ the trait `TypedPath` is not implemented for `std::option::Option<MyTypedPathStruct>`
|
= note: required because of the requirements on the impl of `FirstElementIs<std::option::Option<MyTypedPathStruct>>` for `(std::option::Option<MyTypedPathStruct>, Extension<Arc<web_axum::Context>>)`
note: required by a bound in `typed_get`
--> …/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-extra-0.3.0/src/routing/mod.rs:36:12
|
36 | T: FirstElementIs<P> + 'static,
| ^^^^^^^^^^^^^^^^^ required by this bound in `typed_get`
Proposal
Please implement TypedPath for Option and/or Result.
Alternatives
Adding a layer that removes all text/plain bodies from error responses, parses the error messages, adjusts status codes, and so on.
Not using TypedPath at all.
The text was updated successfully, but these errors were encountered:
Sounds good! I'm not quite sure what needs to be done but I have hunch its more about adding new impls for FirstElementIs than TypedPath.
In the same vein I think we should consider adding a way to use a different rejection such that you don't need to use Option/Result in each handler. Perhaps something the impls From<PathRejection> for YourNewRejection. I think thats a separate feature though.
Feature Request
Motivation
When path extraction fails, I want to send an empty 404 response with no error message. The default error message exposes implementation details of my application to clients, and axum normally sends status code 400 instead of 404 in this situation.
With ordinary extractors like
Path
, this is simple: take anOption<Path<_>>
orResult<Path<_>, PathRejection>
instead of simplyPath<_>
, and then handle the failure as needed. But this is not allowed when usingTypedPath
becauseOption
andResult
don't implement it:Proposal
Please implement
TypedPath
forOption
and/orResult
.Alternatives
text/plain
bodies from error responses, parses the error messages, adjusts status codes, and so on.TypedPath
at all.The text was updated successfully, but these errors were encountered: