diff options
author | Josh McKinney <joshka@users.noreply.github.com> | 2023-04-12 19:02:13 -0700 |
---|---|---|
committer | D. Scott Boggs <scott@tams.tech> | 2023-09-01 07:51:59 -0400 |
commit | b0ea145b47548c797b2f7b1476aaa8e1c8f5d402 (patch) | |
tree | bdbf496ae0afcfe288911033d5cc467b94863fa4 | |
parent | 76681b4675b20c16c1cac5468e024b9a7f8e5235 (diff) |
refactor: use tracing for registration
-rw-r--r-- | src/registration.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/registration.rs b/src/registration.rs index 832edaf..c260001 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -1,10 +1,10 @@ -use log::{as_debug, as_serde, debug, error, trace}; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use reqwest::Client; +use tracing::{debug, error, trace}; use uuid::Uuid; use crate::{ - entities::forms, entities::prelude::*, helpers::read_response::read_response, log_serde, Data, + entities::forms, entities::prelude::*, helpers::read_response::read_response, Data, Error, Mastodon, Result, }; @@ -20,7 +20,7 @@ pub struct Registration { force_login: bool, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct OAuth { client_id: String, client_secret: String, @@ -32,7 +32,7 @@ fn default_redirect_uri() -> String { DEFAULT_REDIRECT_URI.to_string() } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct AccessToken { access_token: String, } @@ -191,24 +191,26 @@ impl Registration { async fn send_app(&self, app: &forms::Application) -> Result<OAuth> { let url = format!("{}/api/v1/apps", self.base); let call_id = Uuid::new_v4(); - debug!(url = url, app = as_serde!(app), call_id = as_debug!(call_id); "registering app"); + debug!(url, ?app, ?call_id, "registering app"); let response = self.client.post(&url).json(&app).send().await?; match response.error_for_status() { Ok(response) => { let response = read_response(response).await?; debug!( - response = as_serde!(response), app = as_serde!(app), - url = url, method = stringify!($method), - call_id = as_debug!(call_id); + ?response, + ?app, + ?url, + method = stringify!($method), + ?call_id, "received API response" ); Ok(response) } Err(err) => { error!( - err = as_debug!(err), url = url, method = stringify!($method), - call_id = as_debug!(call_id); + ?err, url, method = stringify!($method), + ?call_id, "error making API request" ); Err(err.into()) @@ -353,17 +355,17 @@ impl Registered { redirect_uri={}", self.base, self.client_id, self.client_secret, code.as_ref(), self.redirect ); - debug!(url = url; "completing registration"); + debug!(url, "completing registration"); let response = self.client.post(&url).send().await?; debug!( - status = log_serde!(response Status), url = url, - headers = log_serde!(response Headers); + status = %response.status(), url, + headers = ?response.headers(), "received API response" ); let token: AccessToken = read_response(response).await?; - debug!(url = url, body = as_serde!(token); "parsed response body"); + debug!(url, body = ?token, "parsed response body"); let data = self.registered(token.access_token); - trace!(auth_data = as_serde!(data); "registered"); + trace!(auth_data = ?data, "registered"); Ok(Mastodon::new(self.client.clone(), data)) } |