Skip to content

Commit eb051e3

Browse files
authored
Adds a handler for 404 errors (oreoslabs#24)
At the moment unregistered routes do not return a 404 error. Follows this as a reference: https://github.com/tokio-rs/axum/blob/main/examples/global-404-handler/src/main.rs
1 parent 522f22b commit eb051e3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

crates/prover/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{net::SocketAddr, time::Duration};
33
use axum::{
44
error_handling::HandleErrorLayer,
55
http::StatusCode,
6+
response::IntoResponse,
67
routing::{get, post},
78
BoxError, Router,
89
};
@@ -33,7 +34,12 @@ pub async fn run_prover(listen: SocketAddr) -> anyhow::Result<()> {
3334
.allow_headers(Any),
3435
);
3536
let listener = TcpListener::bind(&listen).await?;
37+
let app = router.fallback(handler_404);
3638
info!("Prover listening on {}", listen);
37-
axum::serve(listener, router).await?;
39+
axum::serve(listener, app).await?;
3840
Ok(())
3941
}
42+
43+
async fn handler_404() -> impl IntoResponse {
44+
(StatusCode::NOT_FOUND, "Not Found")
45+
}

crates/server/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ pub async fn run_server(
148148
);
149149

150150
let listener = TcpListener::bind(&listen).await?;
151+
let app = router.fallback(handler_404);
151152
info!("Server listening on {}", listen);
152-
axum::serve(listener, router).await?;
153+
axum::serve(listener, app).await?;
153154
Ok(())
154155
}
156+
157+
async fn handler_404() -> impl IntoResponse {
158+
(StatusCode::NOT_FOUND, "Not Found")
159+
}

0 commit comments

Comments
 (0)