From 24c158a62014d0c8fd54f85415c291e94be57a3d Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 6 May 2021 19:53:51 -0700 Subject: fix(utils): no timeout on request, implements safe guards against rate-limiting --- src/structures.rs | 10 ++++++++++ src/utils.rs | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/structures.rs b/src/structures.rs index 13f904d..0e9f227 100644 --- a/src/structures.rs +++ b/src/structures.rs @@ -10,6 +10,16 @@ pub struct GitHubAPIResponse { pub tree: Vec, pub truncated: bool, } +impl Default for GitHubAPIResponse { + fn default() -> Self { + GitHubAPIResponse { + sha: "rate limited".to_string(), + url: "rate limited".to_string(), + tree: vec![], + truncated: false, + } + } +} #[derive(Serialize, Deserialize, Debug)] pub struct GitHubAPIResponseTree { diff --git a/src/utils.rs b/src/utils.rs index bf10d71..b4672e0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -18,9 +18,9 @@ pub async fn github_api() -> Result() .limit(20_000_000) .await @@ -31,7 +31,7 @@ pub async fn github_api() -> Result Vec { let mut languages = vec![]; - for i in github_api().await.unwrap().tree { + for i in github_api().await.unwrap_or_default().tree { if i._type == "tree" { languages.push(i.path); } -- cgit v1.2.3