Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion crates/lib/docs_rs_repository_stats/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ impl GitHub {
let status = response.status();
let body = response.text().await?;

if status == StatusCode::FORBIDDEN
if status == StatusCode::TOO_MANY_REQUESTS {
Err(RateLimitReached.into())
} else if status == StatusCode::FORBIDDEN
&& let Ok(api_error) = serde_json::from_str::<ApiError>(&body)
&& (api_error
.documentation_url
Expand Down Expand Up @@ -473,4 +475,28 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn test_429_rate_limit() -> Result<()> {
let config = github_config()?;
let (mut server, updater) = mock_server_and_github(&config).await;

let _m1 = server
.mock("POST", "/graphql")
.with_header("content-type", "application/json")
.with_status(429)
.create();

assert!(
updater
.fetch_repository(
&repository_name("https://gitlab.com/foo/bar").expect("repository_name failed"),
)
.await
.unwrap_err()
.is::<RateLimitReached>()
);

Ok(())
}
}
Loading