File tree Expand file tree Collapse file tree
crates/lib/docs_rs_repository_stats/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -200,7 +200,9 @@ impl GitHub {
200200 let status = response. status ( ) ;
201201 let body = response. text ( ) . await ?;
202202
203- if status == StatusCode :: FORBIDDEN
203+ if status == StatusCode :: TOO_MANY_REQUESTS {
204+ Err ( RateLimitReached . into ( ) )
205+ } else if status == StatusCode :: FORBIDDEN
204206 && let Ok ( api_error) = serde_json:: from_str :: < ApiError > ( & body)
205207 && ( api_error
206208 . documentation_url
@@ -473,4 +475,28 @@ mod tests {
473475
474476 Ok ( ( ) )
475477 }
478+
479+ #[ tokio:: test]
480+ async fn test_429_rate_limit ( ) -> Result < ( ) > {
481+ let config = github_config ( ) ?;
482+ let ( mut server, updater) = mock_server_and_github ( & config) . await ;
483+
484+ let _m1 = server
485+ . mock ( "POST" , "/graphql" )
486+ . with_header ( "content-type" , "application/json" )
487+ . with_status ( 429 )
488+ . create ( ) ;
489+
490+ assert ! (
491+ updater
492+ . fetch_repository(
493+ & repository_name( "https://gitlab.com/foo/bar" ) . expect( "repository_name failed" ) ,
494+ )
495+ . await
496+ . unwrap_err( )
497+ . is:: <RateLimitReached >( )
498+ ) ;
499+
500+ Ok ( ( ) )
501+ }
476502}
You can’t perform that action at this time.
0 commit comments