Skip to content

Any way to render errors as late as possible? #932

Answered by davidpdrsn
RAnders00 asked this question in Q&A
Discussion options

You must be logged in to vote

For 404s axum has Router::falback but we don't have something like that for 405s. That is because there isn't one single method router. When you do get(foo) in one place and post(bar) somewhere, those two don't know about each other and thus cannot coordinate their fallbacks.

So to handle this in one place you have to write a middleware that checks the response status code. I don't think thats a hack especially because returning 405 from domain logic is very rare, so if you see one its probably safe to assume its from axum and thus valid to override the response body.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@RAnders00
Comment options

@paolobarbolini
Comment options

@davidpdrsn
Comment options

@RAnders00
Comment options

Answer selected by RAnders00
Comment options

You must be logged in to vote
1 reply
@LyonRust
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants