From d6b609e6409180f381c36a1d1b473eea9ebd5f4f Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 17 Mar 2020 16:53:31 -0500 Subject: [PATCH] Print request error resposnses if present --- src/requests.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/requests.rs b/src/requests.rs index fc889d2..c5ed805 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -20,7 +20,7 @@ pub async fn fetch_actor( let key_id = state.generate_url(UrlKind::MainKey); - let actor: AcceptedActors = client + let mut res = client .get(actor_id.as_str()) .header("Accept", "application/activity+json") .signature(&Config::default(), key_id, |signing_string| { @@ -31,14 +31,24 @@ pub async fn fetch_actor( .map_err(|e| { error!("Couldn't send request to {} for actor, {}", actor_id, e); MyError::SendRequest - })? - .json() - .await - .map_err(|e| { - error!("Coudn't fetch actor from {}, {}", actor_id, e); - MyError::ReceiveResponse })?; + if !res.status().is_success() { + error!("Invalid status code for actor fetch, {}", res.status()); + if let Ok(bytes) = res.body().await { + if let Ok(s) = String::from_utf8(bytes.as_ref().to_vec()) { + error!("Response, {}", s); + } + } + + return Err(MyError::Status); + } + + let actor: AcceptedActors = res.json().await.map_err(|e| { + error!("Coudn't fetch actor from {}, {}", actor_id, e); + MyError::ReceiveResponse + })?; + state.cache_actor(actor_id.to_owned(), actor.clone()).await; Ok(actor) @@ -86,7 +96,7 @@ where let item_string = serde_json::to_string(item)?; - let res = client + let mut res = client .post(inbox.as_str()) .header("Accept", "application/activity+json") .header("Content-Type", "application/activity+json") @@ -107,6 +117,11 @@ where if !res.status().is_success() { error!("Invalid response status from {}, {}", inbox, res.status()); + if let Ok(bytes) = res.body().await { + if let Ok(s) = String::from_utf8(bytes.as_ref().to_vec()) { + error!("Response, {}", s); + } + } return Err(MyError::Status); }