diff --git a/src/archival/archival_response.rs b/src/archival/archival_response.rs index 2d1bbda..9f22ea0 100644 --- a/src/archival/archival_response.rs +++ b/src/archival/archival_response.rs @@ -1,4 +1,5 @@ use serde::Deserialize; +use std::fmt; #[derive(Deserialize, Debug, PartialEq)] pub struct ArchivalResponse { @@ -13,7 +14,7 @@ pub struct ArchivalErrorResponse { pub status_ext: String, } -#[derive(Default, Debug, Clone, PartialEq, Deserialize)] +#[derive(Default, Clone, PartialEq, Deserialize)] pub struct ArchivalStatusResponse { pub duration_sec: Option, pub http_status: Option, @@ -23,10 +24,34 @@ pub struct ArchivalStatusResponse { pub timestamp: Option, } -#[derive(Default, Debug, Clone, PartialEq, Deserialize)] +#[derive(Default, Clone, PartialEq, Deserialize)] pub struct ArchivalStatusErrorResponse { pub job_id: String, - pub message: String, - pub status_ext: String, + pub message: Option, + pub status_ext: Option, pub status: Option, } + +impl fmt::Debug for ArchivalStatusResponse { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Archival Status Response") + .field("duration_sec", &self.duration_sec.unwrap_or_default()) + .field("http_status", &self.http_status.unwrap_or_default()) + .field("job_id", &self.job_id) + .field("original_url", &self.original_url.as_deref().unwrap_or("")) + .field("status", &self.status) + .field("timestamp", &self.timestamp.as_deref().unwrap_or("")) + .finish() + } +} + +impl fmt::Debug for ArchivalStatusErrorResponse { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Archival Status Error Response") + .field("job_id", &self.job_id) + .field("message", &self.message.as_deref().unwrap_or("")) // Unwrap Option or use an empty string + .field("status_ext", &self.status_ext.as_deref().unwrap_or("")) // Unwrap Option or use an empty string + .field("status", &self.status.as_deref().unwrap_or("")) // Unwrap Option or use an empty string + .finish() + } +} diff --git a/src/archival/utils.rs b/src/archival/utils.rs index 627575d..e4a8c54 100644 --- a/src/archival/utils.rs +++ b/src/archival/utils.rs @@ -126,9 +126,15 @@ pub async fn make_archival_status_request( let response_text = response.text().await?; if let Ok(res) = serde_json::from_str::(&response_text) { - if res.status != "error" { - return Ok(res); - } + return if res.status != "error" { + Ok(res) + } else { + let archival_status_error_response = + serde_json::from_str::(&response_text)?; + Err(ArchivalError::StatusRequestErrorResponse( + archival_status_error_response, + )) + }; } if let Ok(e) = serde_json::from_str::(&response_text) { return Err(ArchivalError::StatusRequestErrorResponse(e)); diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 18087f9..e885dc7 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -74,7 +74,8 @@ pub async fn start(pool: &PgPool) { Some(Commands::CheckStatus { job_id }) => { match utils::get_job_id_status(job_id.as_str(), pool).await { Ok(res) => { - println!("Status: {}", res.status) + println!("Status: {}", res.status); + println!("{:?}", res) } Err(e) => { println!("Failed: {}", e) diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index 9e44dee..1065782 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -86,22 +86,22 @@ impl Settings { pub fn init_logger(&self) { let mut builder = Builder::new(); - - if self.logs.debug { - builder.filter(None, LevelFilter::Debug); - } - if self.logs.info { - builder.filter(None, LevelFilter::Info); + if self.logs.error { + builder.filter(None, LevelFilter::Error); } if self.logs.warning { builder.filter(None, LevelFilter::Warn); } - if self.logs.error { - builder.filter(None, LevelFilter::Error); + if self.logs.info { + builder.filter(None, LevelFilter::Info); + } + if self.logs.debug { + builder.filter(None, LevelFilter::Debug); } if !self.logs.debug && !self.logs.info && !self.logs.warning && !self.logs.error { builder.filter(None, LevelFilter::Off); } + builder.filter_module("sqlx", LevelFilter::Info); builder.filter_module("hyper", LevelFilter::Info); builder.filter_module("reqwest", LevelFilter::Info);