Skip to content

Invoke async code in ResponseError trait method error_response #2593

Answered by aliemjay
mellowagain asked this question in Q&A
Discussion options

You must be logged in to vote

I recommend rendering a simple response in ResponseError and then using a middleware for fully rendering the error page. With this approach you have the luxury of async as well as having HttpRequest.

In the middleware, you can downcast HttpResponse::error() to get the underlying error. You also have the option to pass arbitrary data from ResponseError::error_response() to the middleware using HttpResponse::extensions().

A related example https://github.com/svenstaro/miniserve/blob/f40e7d4c66775c8f89564ee1b2bbe4b2d7cfc660/src/errors.rs#L112

Replies: 1 comment 1 reply

Comment options

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

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