Skip to content

Commit

Permalink
feat(term): handle github secondary rate limit error
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Jul 9, 2024
1 parent b692057 commit 9f690c6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions crates/synd_term/src/client/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ 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),
}

impl From<octocrab::Error> 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),
}
}
Expand Down

0 comments on commit 9f690c6

Please sign in to comment.