From 6f033de946a087c192b997b8b545631c76075ea5 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 30 Apr 2024 16:47:34 +0200 Subject: [PATCH] fix: try fetching following/followers, dont fail --- src/server/fetcher.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/server/fetcher.rs b/src/server/fetcher.rs index 8d8e8ff8..40a7ee52 100644 --- a/src/server/fetcher.rs +++ b/src/server/fetcher.rs @@ -88,20 +88,30 @@ impl Fetcher for Context { // TODO try fetching these numbers from audience/generator fields to avoid making 2 more GETs if let Some(followers_url) = &user_model.followers { - let user_followers = Self::request( - Method::GET, followers_url, None, &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), - ).await?.json::().await?; - if let Some(total) = user_followers.total_items() { - user_model.followers_count = total as i64; + let req = Self::request( + Method::GET, followers_url, None, + &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), + ).await; + if let Ok(res) = req { + if let Ok(user_followers) = res.json::().await { + if let Some(total) = user_followers.total_items() { + user_model.followers_count = total as i64; + } + } } } if let Some(following_url) = &user_model.following { - let user_following = Self::request( - Method::GET, following_url, None, &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), - ).await?.json::().await?; - if let Some(total) = user_following.total_items() { - user_model.following_count = total as i64; + let req = Self::request( + Method::GET, following_url, None, + &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), + ).await; + if let Ok(res) = req { + if let Ok(user_following) = res.json::().await { + if let Some(total) = user_following.total_items() { + user_model.following_count = total as i64; + } + } } }