From a1f1ee51d0185273ce6694f509914e85981b14d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Berthaud-M=C3=BCller?= Date: Sat, 23 Apr 2022 00:45:57 +0200 Subject: [PATCH] use logger instead of print --- src/config.rs | 6 +++--- src/dns/dns_connector.rs | 2 +- src/main.rs | 5 ----- src/models/errors.rs | 6 ++++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/config.rs b/src/config.rs index e286f03..2276ced 100644 --- a/src/config.rs +++ b/src/config.rs @@ -45,7 +45,7 @@ impl<'r> FromRequest<'r> for DnsClient { let config = try_outcome!(request.guard::<&State>().await); match DnsClient::new(config.dns.server).await { Err(e) => { - println!("Failed to connect to DNS server: {}", e); + error!("Failed to connect to DNS server: {}", e); Outcome::Failure((Status::InternalServerError, ())) }, Ok(c) => Outcome::Success(c) @@ -60,7 +60,7 @@ impl<'r> FromRequest<'r> for Box { let config = try_outcome!(request.guard::<&State>().await); match DnsClient::new(config.dns.server).await { Err(e) => { - println!("Failed to connect to DNS server: {}", e); + error!("Failed to connect to DNS server: {}", e); Outcome::Failure((Status::InternalServerError, ())) }, Ok(c) => Outcome::Success(Box::new(DnsConnectorClient::new(c))) @@ -75,7 +75,7 @@ impl<'r> FromRequest<'r> for Box { let config = try_outcome!(request.guard::<&State>().await); match DnsClient::new(config.dns.server).await { Err(e) => { - println!("Failed to connect to DNS server: {}", e); + error!("Failed to connect to DNS server: {}", e); Outcome::Failure((Status::InternalServerError, ())) }, Ok(c) => Outcome::Success(Box::new(DnsConnectorClient::new(c))) diff --git a/src/dns/dns_connector.rs b/src/dns/dns_connector.rs index 0a7596e..87f7578 100644 --- a/src/dns/dns_connector.rs +++ b/src/dns/dns_connector.rs @@ -54,7 +54,7 @@ impl std::fmt::Display for DnsConnectorError { write!(f, "DNS client error: {}", e) }, DnsConnectorError::ResponceNotOk { code, zone } => { - write!(f, "Query for zone {} failed with code {}", zone, code) + write!(f, "Query for zone \"{}\" failed with code \"{}\"", zone, code) } } diff --git a/src/main.rs b/src/main.rs index 9ad2e54..3775b50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,10 +25,6 @@ pub struct DbConn(diesel::SqliteConnection); #[launch] async fn rocket() -> _ { - //let app_config = config::load("config.toml".into()); - //println!("{:#?}", app_config); - - let figment = Figment::from(rocket::Config::default()) .merge(Toml::file(Env::var_or("NOMILO_CONFIG", "nomilo.toml")).nested()) .merge(Env::prefixed("NOMILO_").ignore(&["PROFILE"]).global()) @@ -41,7 +37,6 @@ async fn rocket() -> _ { exit(1); } }; - //let app_config = .expect("unable to load configuration"); rocket::custom(figment) .manage(app_config) diff --git a/src/models/errors.rs b/src/models/errors.rs index 130d876..7667b13 100644 --- a/src/models/errors.rs +++ b/src/models/errors.rs @@ -102,10 +102,11 @@ impl From for ErrorResponse { impl From> for ErrorResponse { fn from(e: Box) -> Self { - println!("{}", e); if e.is_proto_error() { + error!("{}", e); return make_500(e); } else { + warn!("{}", e); let error = ErrorResponse::new( Status::NotFound, "Zone could not be found".into() @@ -168,6 +169,7 @@ impl From for (Status, ErrorResponse) { // TODO: change for Display trait pub fn make_500(e: E) -> ErrorResponse { - println!("Making 500 for Error: {:?}", e); + error!("Making 500 for Error: {:?}", e); + ErrorResponse::new(Status::InternalServerError, "An unexpected error occured.".into()) }