use axum::{ http::StatusCode, response::{IntoResponse, Response}, }; #[derive(Debug)] pub struct AppError(anyhow::Error); // Tell axum how to convert `AppError` into a response. impl IntoResponse for AppError { fn into_response(self) -> Response { tracing::error!("Application error: {:#}", self.0); (StatusCode::INTERNAL_SERVER_ERROR, "Something went wrong").into_response() } } // 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 From for AppError where E: Into, { fn from(err: E) -> Self { Self(err.into()) } }