Skip to content

Commit ee7dd4f

Browse files
simonc56Copilot
andauthored
catch JSONDecodeError if response body is not json
Co-authored-by: Copilot <[email protected]>
1 parent c6eee75 commit ee7dd4f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

trakt/api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,16 @@ def refresh_token(self):
250250
response = self.client.post('oauth/token', data)
251251
self.refresh_attempts = 0
252252
except (OAuthException, BadRequestException) as e:
253-
error = e.response.json().get("error") if e.response is not None else "No error description"
254-
error_description = e.response.json().get("error_description") if e.response is not None else ""
253+
if e.response is not None:
254+
try:
255+
error = e.response.json().get("error")
256+
error_description = e.response.json().get("error_description")
257+
except JSONDecodeError:
258+
error = "Invalid JSON response"
259+
error_description = e.response.text
260+
else:
261+
error = "No error description"
262+
error_description = ""
255263
self.logger.error(
256264
"%s - Unable to refresh expired OAuth token (%s) %s",
257265
e.http_code, error, error_description

0 commit comments

Comments
 (0)