File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -123,13 +123,24 @@ def authenticate_with_github_token(api_origin: str, interactive: bool = True):
123123 )
124124
125125 if response .status_code == 200 :
126- api_key = response .json ()["api_key" ]
127- save_api_key (api_key )
128- if interactive :
129- print ("✅ Authenticated using GitHub CLI!" )
130- return api_key
126+ try :
127+ api_key = response .json ()["api_key" ]
128+ save_api_key (api_key )
129+ if interactive :
130+ print ("✅ Authenticated using GitHub CLI!" )
131+ return api_key
132+ except (KeyError , ValueError ) as e :
133+ if interactive :
134+ print ("⚠️ Invalid response from authentication server" )
135+ logger .debug (f"Invalid JSON response on success: { e } , body: { response .text [:200 ]} " )
136+ return None
131137 else :
132- error_msg = response .json ().get ("error_description" , "Unknown error" )
138+ try :
139+ error_msg = response .json ().get ("error_description" , "Unknown error" )
140+ except ValueError :
141+ error_msg = f"HTTP { response .status_code } "
142+ logger .debug (f"Non-JSON error response: { response .text [:200 ]} " )
143+
133144 if interactive :
134145 print (f"⚠️ GitHub token authentication failed: { error_msg } " )
135146 logger .debug (f"GitHub token auth failed: { response .status_code } - { error_msg } " )
You can’t perform that action at this time.
0 commit comments