@@ -115,8 +115,16 @@ async def _get_credentials(self) -> bool:
115
115
116
116
return await self ._validate_credentials ()
117
117
118
- except ValueError as e :
119
- logger .error ("Failed to get OAuth2.0 credentials: %s" , str (e ), exc_info = True )
118
+ except OAuthCodeFlowError as e :
119
+ logger .error ("Failed to get OAuth2.0 credentials using code flow: %s" , str (e ), exc_info = True )
120
+ return False
121
+
122
+ except OAuthRefreshTokenError as e :
123
+ logger .error ("Failed to get OAuth2.0 credentials using refresh token: %s" , str (e ), exc_info = True )
124
+ return False
125
+
126
+ except Exception as e :
127
+ logger .error ("Failed to get OAuth2.0 credentials due to unexpected error: %s" , str (e ), exc_info = True )
120
128
return False
121
129
122
130
async def _initiate_authorization_code_flow_console (self ) -> None :
@@ -139,6 +147,7 @@ async def _initiate_authorization_code_flow_console(self) -> None:
139
147
except OAuthCodeFlowError as e :
140
148
logger .error ("Failed to complete OAuth2.0 authentication for provider Error: %s" , str (e ), exc_info = True )
141
149
await self ._shutdown_code_flow_dispatch [self .execution_mode ]()
150
+ raise e
142
151
143
152
async def _initiate_authorization_code_flow_server (self ) -> None :
144
153
"""
@@ -155,6 +164,7 @@ async def _initiate_authorization_code_flow_server(self) -> None:
155
164
except OAuthCodeFlowError as e :
156
165
logger .error ("Failed to complete OAuth2.0 authentication for provider Error: %s" , str (e ), exc_info = True )
157
166
await self ._shutdown_code_flow_dispatch [self .execution_mode ]()
167
+ raise e
158
168
159
169
async def _send_oauth_authorization_request (self ) -> None :
160
170
"""
@@ -184,13 +194,13 @@ async def _get_access_token_with_refresh_token(self) -> None:
184
194
"""
185
195
try :
186
196
if not self .authentication_provider .refresh_token :
187
- raise ValueError ("Refresh token is missing during the refresh token request." )
197
+ raise OAuthRefreshTokenError ("Refresh token is missing during the refresh token request." )
188
198
189
199
if not self .authentication_provider .client_id :
190
- raise ValueError ("Client ID is missing during the refresh token request." )
200
+ raise OAuthRefreshTokenError ("Client ID is missing during the refresh token request." )
191
201
192
202
if not self .authentication_provider .client_secret :
193
- raise ValueError ("Client secret is missing during the refresh token request." )
203
+ raise OAuthRefreshTokenError ("Client secret is missing during the refresh token request." )
194
204
195
205
body_data : RefreshTokenRequest = RefreshTokenRequest (
196
206
client_id = self ._authentication_provider .client_id ,
@@ -206,20 +216,21 @@ async def _get_access_token_with_refresh_token(self) -> None:
206
216
body_data = body_data .model_dump ())
207
217
208
218
if response is None :
209
- raise ValueError ("Invalid response received while making refresh token request." )
219
+ raise OAuthRefreshTokenError ("Invalid response received while making refresh token request." )
210
220
211
221
if not response .status_code == 200 :
212
222
await self ._response_manager ._handle_oauth_authorization_response_codes (
213
223
response , self ._authentication_provider )
214
224
215
225
if response .json ().get ("access_token" ) is None :
216
- raise ValueError ("Access token not in successful token request response payload." )
226
+ raise OAuthRefreshTokenError ("Access token not in successful token request response payload." )
217
227
218
228
if response .json ().get ("expires_in" ) is None :
219
- raise ValueError ("Access token expiration time not in successful token request response payload." )
229
+ raise OAuthRefreshTokenError (
230
+ "Access token expiration time not in successful token request response payload." )
220
231
221
232
if response .json ().get ("refresh_token" ) is None :
222
- raise ValueError ("Refresh token not in successful token request response payload." )
233
+ raise OAuthRefreshTokenError ("Refresh token not in successful token request response payload." )
223
234
224
235
self .authentication_provider .access_token = response .json ().get ("access_token" )
225
236
@@ -228,8 +239,9 @@ async def _get_access_token_with_refresh_token(self) -> None:
228
239
229
240
self .authentication_provider .refresh_token = response .json ().get ("refresh_token" )
230
241
231
- except OAuthRefreshTokenError as e :
242
+ except Exception as e :
232
243
logger .error ("Failed to complete OAuth2.0 authentication for provider Error: %s" , str (e ), exc_info = True )
244
+ raise OAuthRefreshTokenError ("Failed to get OAuth2.0 credentials using refresh token." ) from e
233
245
234
246
async def _spawn_oauth_client_server (self ) -> None :
235
247
"""
0 commit comments