@@ -34,18 +34,41 @@ def github_api_request(self, endpoint):
3434
3535 token = self .get_github_token ()
3636 if token :
37- headers ['Authorization' ] = f'token { token } '
37+ headers ['Authorization' ] = f'Bearer { token } '
3838
3939 try :
4040 req = urllib .request .Request (url , headers = headers )
4141 with urllib .request .urlopen (req , timeout = 10 ) as response :
4242 return json .loads (response .read ().decode ())
4343 except urllib .error .HTTPError as e :
44+ # Try to get detailed error message from response body
45+ error_msg = None
46+ try :
47+ error_body = e .read ().decode ()
48+ error_data = json .loads (error_body )
49+ error_msg = error_data .get ('message' , '' )
50+ except :
51+ pass
52+
4453 if e .code == 403 :
45- print (f"⚠️ GitHub API rate limit reached. Set GITHUB_TOKEN env var for higher limits." )
54+ if error_msg :
55+ print (f"⚠️ GitHub API error (403): { error_msg } " )
56+ if 'rate limit' in error_msg .lower ():
57+ print (f"💡 Set GITHUB_TOKEN env var for higher rate limits." )
58+ elif 'credentials' in error_msg .lower () or 'token' in error_msg .lower ():
59+ print (f"💡 Check that GITHUB_TOKEN has the correct permissions." )
60+ else :
61+ print (f"⚠️ GitHub API access denied (403). Set GITHUB_TOKEN env var with proper permissions." )
62+ return None
63+ elif e .code == 404 :
64+ print (f"⚠️ GitHub API endpoint not found (404): { endpoint } " )
65+ return None
66+ else :
67+ if error_msg :
68+ print (f"⚠️ GitHub API error { e .code } : { error_msg } " )
69+ else :
70+ print (f"⚠️ GitHub API error { e .code } : { e .reason } " )
4671 return None
47- print (f"⚠️ GitHub API error { e .code } : { e .reason } " )
48- return None
4972 except Exception as e :
5073 print (f"⚠️ Error fetching from GitHub API: { e } " )
5174 return None
0 commit comments