@@ -195,16 +195,42 @@ def request(self, n_pages=100, n_per_page=50):
195195 auth = self .auth ,
196196 )
197197 if ii_request .status_code != 200 :
198+ # Check for common error cases and provide helpful messages
199+ if ii_request .status_code == 403 :
200+ try :
201+ error_data = ii_request .json ()
202+ error_message = error_data .get ("message" , "" )
203+ if "rate limit" in error_message .lower ():
204+ raise Exception (
205+ f"GitHub API rate limit exceeded. { error_message } \n "
206+ "Please wait before making more requests, or use an authentication token with higher rate limits."
207+ )
208+ else :
209+ # Generic 403 - likely a permissions issue
210+ raise Exception (
211+ f"GitHub API access forbidden. { error_message } \n "
212+ "This usually means your authentication token doesn't have the required permissions.\n "
213+ "Please check that your token has the necessary scopes for this repository."
214+ )
215+ except (ValueError , KeyError ):
216+ pass
198217 raise Exception (
199218 "Query failed to run by returning code of {}. {}" .format (
200219 ii_request .status_code , ii_gql_query
201220 )
202221 )
203- if "errors" in ii_request .json ().keys ():
222+ errors = ii_request .json ().get ("errors" )
223+ if errors :
224+ # Check for rate limit errors in GraphQL response
225+ for error in errors :
226+ if error .get ("type" ) == "RATE_LIMITED" :
227+ error_message = error .get ("message" , "Rate limit exceeded" )
228+ raise Exception (
229+ f"GitHub API rate limit exceeded. { error_message } \n "
230+ "Please wait before making more requests, or use an authentication token with higher rate limits."
231+ )
204232 raise Exception (
205- "Query failed to run with error {}. {}" .format (
206- ii_request .json ()["errors" ], ii_gql_query
207- )
233+ "Query failed to run with error {}. {}" .format (errors , ii_gql_query )
208234 )
209235 self .last_request = ii_request
210236
0 commit comments