use anyhow::Error as AnyError; use axum::http::{StatusCode, Uri}; use axum::response::{IntoResponse, Response}; use axum::{routing::get, Router}; pub fn get_router() -> Router { Router::new() .route("/", get(|| async { "Hello, world!" })) .fallback(fallback) } async fn fallback(uri: Uri) -> (StatusCode, String) { (StatusCode::NOT_FOUND, format!("No route for {uri}")) } struct AppError(AnyError); // To automatically convert `AppError` into a response impl IntoResponse for AppError { fn into_response(self) -> Response { ( StatusCode::INTERNAL_SERVER_ERROR, format!("Internal Server Error: {}", self.0), ) .into_response() } } // To automatically convert `AnyError` into `AppError` impl From for AppError where E: Into, { fn from(err: E) -> Self { Self(err.into()) } }