From 9f690c675870b359150738c66029224f5c94b52f Mon Sep 17 00:00:00 2001 From: ymgyt Date: Tue, 9 Jul 2024 11:09:04 +0900 Subject: [PATCH] feat(term): handle github secondary rate limit error --- crates/synd_term/src/client/github/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/synd_term/src/client/github/mod.rs b/crates/synd_term/src/client/github/mod.rs index 1869d14e..95657e9a 100644 --- a/crates/synd_term/src/client/github/mod.rs +++ b/crates/synd_term/src/client/github/mod.rs @@ -15,6 +15,9 @@ use crate::{ pub(crate) enum GithubError { #[error("invalid credential. please make sure a valid PAT is set")] BadCredential, + // https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits + #[error("secondary rate limits exceeded")] + SecondaryRateLimit, #[error("github api error: {0}")] Api(octocrab::Error), } @@ -22,14 +25,13 @@ pub(crate) enum GithubError { impl From for GithubError { fn from(err: octocrab::Error) -> Self { match &err { - octocrab::Error::GitHub { source, .. } => { - // octocrab does not re-export http crate - if source.status_code.as_u16() == 401 { - GithubError::BadCredential - } else { - GithubError::Api(err) + octocrab::Error::GitHub { source, .. } => match source.status_code.as_u16() { + 401 => GithubError::BadCredential, + 403 if source.message.contains("secondary rate limit") => { + GithubError::SecondaryRateLimit } - } + _ => GithubError::Api(err), + }, _ => GithubError::Api(err), } }