Debug nonsense

This commit is contained in:
Daniel Flanagan 2024-08-05 15:17:46 -05:00
parent 38912b506b
commit f017cd5e1f
2 changed files with 27 additions and 7 deletions

View file

@ -9,23 +9,29 @@ use serde::de;
pub struct Client {
client: ClientWithMiddleware,
base_url: Url,
/// If true AND compiled in debug mode, debug traces will be output for requests and responses
debug: bool,
}
pub trait ResourceRequest {
async fn is_debug(&self) -> bool;
async fn res<T: de::DeserializeOwned>(self) -> Result<T>;
}
impl ResourceRequest for RequestBuilder {
async fn res<T: de::DeserializeOwned>(self) -> Result<T> {
// TODO: make this a field on this struct or something?
/*
use tracing::debug;
let body = self.send().await?.text().await?;
debug!(body);
serde_json::from_str(&body).map_err(|e| e.into())
*/
self.send().await?.json().await.map_err(|e| e.into())
if self.is_debug() {
#[cfg(debug_assertions)]
debug!(body);
}
serde_json::from_str(&body).map_err(|e| e.into())
// self.send().await?.json().await.map_err(|e| e.into())
}
}
@ -67,4 +73,12 @@ impl Client {
pub async fn get<T: de::DeserializeOwned>(&self, rel_url_path: &str) -> Result<T> {
self.request::<T>(Method::GET, rel_url_path).await
}
pub async fn post<T: de::DeserializeOwned, S: se::SerializeOwnded>(
&self,
rel_url_path: &str,
body: &S,
) -> Result<T> {
self.request::<T>(Method::POST, rel_url_path).await
}
}

View file

@ -54,7 +54,13 @@ impl Tui {
eprintln!("{sig:#?}");
println!("{sig:#?}");
info!("{sig:#?}");
signal_sender.send(Event::Quit).unwrap();
match signal_sender.send(Event::Quit) {
Ok(_) => {}
Err(_) => {
error!("Failed to send quit signal event");
// TODO: kill the app
}
}
});
let tick_rate = std::time::Duration::from_millis(1000);