Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion trakt/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ class OAuthException(TraktException):


class OAuthRefreshException(OAuthException):
"""Raised when OAuth token refresh fails."""

message = 'Unauthorized - OAuth token refresh failed'

def __init__(self, response=None):
super().__init__(response)
Comment on lines 75 to 77
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in commit d65434c by adding a class docstring to OAuthRefreshException.

self.data = self.response.json()
self.data = self._error_data(self.response)

@property
def error(self):
Comment thread
glensc marked this conversation as resolved.
Expand All @@ -83,6 +85,30 @@ def error(self):
def error_description(self):
return self.data["error_description"]

@classmethod
def _error_data(cls, response):
data = cls._response_json(response)

return {
"error": data.get("error", ""),
"error_description": data.get("error_description", ""),
}

@staticmethod
def _response_json(response):
if response is None:
return {}

try:
data = response.json()
except (ValueError, AttributeError):
return {}

if not isinstance(data, dict):
return {}

return data
Comment on lines 76 to +110


class ForbiddenException(TraktException):
"""TraktException type to be raised when a 403 return code is received"""
Expand Down