Skip to content

Commit

Permalink
Add fallback handler to axum Router (#258)
Browse files Browse the repository at this point in the history
By default the fallback handler now logs the path that could not be
found.
This can be vital for debugging, as otherwise there is no feedback on
the server if a method is called that isn't registered.

Signed-off-by: Leon Matthes <[email protected]>
  • Loading branch information
LeonMatthesKDAB authored Jan 28, 2025
1 parent a532ee1 commit 52f095f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions dapr/src/server/http.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{
extract::{Path, State},
extract::{OriginalUri, Path, State},
http::StatusCode,
response::IntoResponse,
routing::{delete, get, put},
Expand Down Expand Up @@ -207,14 +207,23 @@ impl DaprHttpServer {
.route(
"/actors/:actor_type/:actor_id/method/timer/:timer_name",
put(invoke_timer).with_state(rt.clone()),
);
)
.fallback(fallback_handler);

self.actor_runtime
.configure_method_routes(app, rt.clone())
.await
}
}

async fn fallback_handler(OriginalUri(uri): OriginalUri) -> impl IntoResponse {
log::warn!("Returning 404 for request: {uri}");
(
StatusCode::NOT_FOUND,
format!("The URI '{uri}' could not be found!"),
)
}

async fn health_check() -> impl IntoResponse {
log::debug!("recieved health check request");
StatusCode::OK
Expand Down

0 comments on commit 52f095f

Please sign in to comment.