Skip to content

Commit bf1eaf2

Browse files
committed
properly handle json exception
1 parent b1d5d05 commit bf1eaf2

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,30 @@ def _make_handled_request(self) -> Any:
217217
data=self.build_refresh_request_body(),
218218
headers=self.build_refresh_request_headers(),
219219
)
220-
response_json = response.json()
220+
221+
try:
222+
response_json = response.json()
223+
except Exception as e:
224+
# if the json could not be parsed, save the exception to raise it later
225+
json_exception = e
226+
221227
try:
222-
# extract the access token and add to secrets to avoid logging the raw value
223-
access_key = self._extract_access_token(response_json)
224-
if access_key:
225-
add_to_secrets(access_key)
228+
if response_json:
229+
# extract the access token and add to secrets to avoid logging the raw value
230+
access_key = self._extract_access_token(response_json)
231+
if access_key:
232+
add_to_secrets(access_key)
226233
except ResponseKeysMaxRecurtionReached as e:
227-
## Could not find the access token in the response, so do nothing
234+
## could not find the access token in the response, so do nothing
228235
pass
236+
229237
# log the response even if the request failed for troubleshooting purposes
230238
self._log_response(response)
231239
response.raise_for_status()
240+
241+
if json_exception:
242+
raise json_exception
243+
232244
return response_json
233245
except requests.exceptions.RequestException as e:
234246
if e.response is not None:

0 commit comments

Comments
 (0)