From 7319430a2fcc0edf38317f86e9ee723bc792854a Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 22 Nov 2024 16:26:04 +0100 Subject: [PATCH] Better error handling --- pdns/recursordist/settings/rust/src/web.rs | 4 ++-- pdns/recursordist/ws-recursor.cc | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pdns/recursordist/settings/rust/src/web.rs b/pdns/recursordist/settings/rust/src/web.rs index 8151c1a3ac..d934f21456 100644 --- a/pdns/recursordist/settings/rust/src/web.rs +++ b/pdns/recursordist/settings/rust/src/web.rs @@ -266,13 +266,13 @@ async fn hello( } let pos = urls.iter().position(|x| String::from("/") + x == path); if pos.is_none() { - println!("{} not found", path); + eprintln!("{} {} not found", rust_request.method(), path); } if rustweb::serveStuff(&request, &mut response).is_err() { // Return 404 not found response. response.status = StatusCode::NOT_FOUND.as_u16(); response.body = NOTFOUND.to_vec(); - println!("{} not found case 2", path); + eprintln!("{} {} not found case 2", rust_request.method(), path); } } } diff --git a/pdns/recursordist/ws-recursor.cc b/pdns/recursordist/ws-recursor.cc index b4fb291ea7..7a1a326198 100644 --- a/pdns/recursordist/ws-recursor.cc +++ b/pdns/recursordist/ws-recursor.cc @@ -993,6 +993,12 @@ static void rustWrapper(const std::function& response.body = e.response().body; response.status = e.response().status; } + catch (const ApiException & e) { + response.setErrorResult(e.what(), 422); + } + catch (const JsonException & e) { + response.setErrorResult(e.what(), 422); + } fromCxxToRust(response, rustResponse); } -- 2.47.2