Skip to content

Commit 10f0e5c

Browse files
authored
Log error when refresh token fails (#81)
2 parents 3cf8771 + ee7dd4f commit 10f0e5c

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

trakt/api.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from trakt import errors
1111
from trakt.config import AuthConfig
1212
from trakt.core import TIMEOUT
13-
from trakt.errors import BadResponseException, OAuthException
13+
from trakt.errors import BadRequestException, BadResponseException, OAuthException
1414

1515
__author__ = 'Elan Ruusamäe'
1616

@@ -249,10 +249,20 @@ def refresh_token(self):
249249
try:
250250
response = self.client.post('oauth/token', data)
251251
self.refresh_attempts = 0
252-
except OAuthException:
253-
self.logger.debug(
254-
"Rejected - Unable to refresh expired OAuth token, "
255-
"refresh_token is invalid"
252+
except (OAuthException, BadRequestException) as e:
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 = ""
263+
self.logger.error(
264+
"%s - Unable to refresh expired OAuth token (%s) %s",
265+
e.http_code, error, error_description
256266
)
257267
return
258268

0 commit comments

Comments
 (0)