use logger instead of print

main
Hannaeko 2022-04-23 00:45:57 +02:00
parent d75e3704e4
commit a1f1ee51d0
4 changed files with 8 additions and 11 deletions

View File

@ -45,7 +45,7 @@ impl<'r> FromRequest<'r> for DnsClient {
let config = try_outcome!(request.guard::<&State<Config>>().await); let config = try_outcome!(request.guard::<&State<Config>>().await);
match DnsClient::new(config.dns.server).await { match DnsClient::new(config.dns.server).await {
Err(e) => { Err(e) => {
println!("Failed to connect to DNS server: {}", e); error!("Failed to connect to DNS server: {}", e);
Outcome::Failure((Status::InternalServerError, ())) Outcome::Failure((Status::InternalServerError, ()))
}, },
Ok(c) => Outcome::Success(c) Ok(c) => Outcome::Success(c)
@ -60,7 +60,7 @@ impl<'r> FromRequest<'r> for Box<dyn RecordConnector> {
let config = try_outcome!(request.guard::<&State<Config>>().await); let config = try_outcome!(request.guard::<&State<Config>>().await);
match DnsClient::new(config.dns.server).await { match DnsClient::new(config.dns.server).await {
Err(e) => { Err(e) => {
println!("Failed to connect to DNS server: {}", e); error!("Failed to connect to DNS server: {}", e);
Outcome::Failure((Status::InternalServerError, ())) Outcome::Failure((Status::InternalServerError, ()))
}, },
Ok(c) => Outcome::Success(Box::new(DnsConnectorClient::new(c))) Ok(c) => Outcome::Success(Box::new(DnsConnectorClient::new(c)))
@ -75,7 +75,7 @@ impl<'r> FromRequest<'r> for Box<dyn ZoneConnector> {
let config = try_outcome!(request.guard::<&State<Config>>().await); let config = try_outcome!(request.guard::<&State<Config>>().await);
match DnsClient::new(config.dns.server).await { match DnsClient::new(config.dns.server).await {
Err(e) => { Err(e) => {
println!("Failed to connect to DNS server: {}", e); error!("Failed to connect to DNS server: {}", e);
Outcome::Failure((Status::InternalServerError, ())) Outcome::Failure((Status::InternalServerError, ()))
}, },
Ok(c) => Outcome::Success(Box::new(DnsConnectorClient::new(c))) Ok(c) => Outcome::Success(Box::new(DnsConnectorClient::new(c)))

View File

@ -54,7 +54,7 @@ impl std::fmt::Display for DnsConnectorError {
write!(f, "DNS client error: {}", e) write!(f, "DNS client error: {}", e)
}, },
DnsConnectorError::ResponceNotOk { code, zone } => { DnsConnectorError::ResponceNotOk { code, zone } => {
write!(f, "Query for zone {} failed with code {}", zone, code) write!(f, "Query for zone \"{}\" failed with code \"{}\"", zone, code)
} }
} }

View File

@ -25,10 +25,6 @@ pub struct DbConn(diesel::SqliteConnection);
#[launch] #[launch]
async fn rocket() -> _ { async fn rocket() -> _ {
//let app_config = config::load("config.toml".into());
//println!("{:#?}", app_config);
let figment = Figment::from(rocket::Config::default()) let figment = Figment::from(rocket::Config::default())
.merge(Toml::file(Env::var_or("NOMILO_CONFIG", "nomilo.toml")).nested()) .merge(Toml::file(Env::var_or("NOMILO_CONFIG", "nomilo.toml")).nested())
.merge(Env::prefixed("NOMILO_").ignore(&["PROFILE"]).global()) .merge(Env::prefixed("NOMILO_").ignore(&["PROFILE"]).global())
@ -41,7 +37,6 @@ async fn rocket() -> _ {
exit(1); exit(1);
} }
}; };
//let app_config = .expect("unable to load configuration");
rocket::custom(figment) rocket::custom(figment)
.manage(app_config) .manage(app_config)

View File

@ -102,10 +102,11 @@ impl From<UserError> for ErrorResponse {
impl From<Box<dyn ConnectorError>> for ErrorResponse { impl From<Box<dyn ConnectorError>> for ErrorResponse {
fn from(e: Box<dyn ConnectorError>) -> Self { fn from(e: Box<dyn ConnectorError>) -> Self {
println!("{}", e);
if e.is_proto_error() { if e.is_proto_error() {
error!("{}", e);
return make_500(e); return make_500(e);
} else { } else {
warn!("{}", e);
let error = ErrorResponse::new( let error = ErrorResponse::new(
Status::NotFound, Status::NotFound,
"Zone could not be found".into() "Zone could not be found".into()
@ -168,6 +169,7 @@ impl From<ErrorResponse> for (Status, ErrorResponse) {
// TODO: change for Display trait // TODO: change for Display trait
pub fn make_500<E: std::fmt::Debug>(e: E) -> ErrorResponse { pub fn make_500<E: std::fmt::Debug>(e: E) -> ErrorResponse {
println!("Making 500 for Error: {:?}", e); error!("Making 500 for Error: {:?}", e);
ErrorResponse::new(Status::InternalServerError, "An unexpected error occured.".into()) ErrorResponse::new(Status::InternalServerError, "An unexpected error occured.".into())
} }