impl anyhow Errors into Axum Responses


Been playing around with reimplementing this site using axum and maud, using incremental static generation.

Took my eyes awhile to see the axum example of how to convert anyhow errors into axum Responses.

Quite simply, it is.

struct AppError(anyhow::Error);

impl IntoResponse for AppError {
    fn into_response(self) -> Response {
            format!("Something went wrong: {}", self.0),

// This enables using `?` on functions that return `Result<_, anyhow::Error>` to turn them into
// `Result<_, AppError>`. That way you don't need to do that manually.
impl<E> From<E> for AppError
    E: Into<anyhow::Error>,
    fn from(err: E) -> Self {