Handle 404 fallback.
This commit is contained in:
+1
-1
@@ -88,6 +88,6 @@ impl ErrorResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_response(status_code: StatusCode, message: impl Into<String>) -> Response {
|
pub fn error_response(status_code: StatusCode, message: impl Into<String>) -> Response {
|
||||||
(status_code, axum::Json(ErrorResponse::new(message))).into_response()
|
(status_code, axum::Json(ErrorResponse::new(message))).into_response()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -30,9 +30,10 @@ async fn main() {
|
|||||||
|
|
||||||
let host = env::var("HOST").expect("HOST must be set");
|
let host = env::var("HOST").expect("HOST must be set");
|
||||||
let port = env::var("PORT").expect("PORT must be set");
|
let port = env::var("PORT").expect("PORT must be set");
|
||||||
let listener = TcpListener::bind(format!("{}:{}", host, port))
|
let addr = format!("{}:{}", host, port);
|
||||||
|
let listener = TcpListener::bind(&addr)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to bind to address");
|
.expect(&format!("Failed to bind to address: {}", addr));
|
||||||
|
|
||||||
tracing::info!("Starting server at {}:{}", host, port);
|
tracing::info!("Starting server at {}:{}", host, port);
|
||||||
axum::serve(listener, routes::create_router(pool).into_make_service())
|
axum::serve(listener, routes::create_router(pool).into_make_service())
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::error::AppError;
|
||||||
|
|
||||||
pub mod dtos;
|
pub mod dtos;
|
||||||
pub mod extractors;
|
pub mod extractors;
|
||||||
pub mod scheduled_transactions;
|
pub mod scheduled_transactions;
|
||||||
@@ -15,5 +17,10 @@ pub fn create_router(pool: sqlx::PgPool) -> axum::Router {
|
|||||||
)
|
)
|
||||||
.nest("/transactions", transactions::create_router()),
|
.nest("/transactions", transactions::create_router()),
|
||||||
)
|
)
|
||||||
|
.fallback(handle_fallback)
|
||||||
.with_state(pool)
|
.with_state(pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_fallback() -> AppError {
|
||||||
|
AppError::NotFound
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user