Skip to content

Commit 75055fe

Browse files
glenscCopilotcodexCopilot
committed
Improve response parsing for OAuthRefreshException
- Handle missing, invalid, or non-dict JSON payloads - Avoid crashes when refresh failures return unexpected bodies - Add fallback type safe values for error, error_description Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: OpenCode (gpt-5.4) <noreply@openai.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent fe8548c commit 75055fe

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

trakt/errors.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,24 @@ class OAuthRefreshException(OAuthException):
7373

7474
def __init__(self, response=None):
7575
super().__init__(response)
76-
self.data = self.response.json()
76+
self.data = self._parse_response(self.response)
77+
78+
@staticmethod
79+
def _parse_response(response):
80+
if response is None:
81+
data = {}
82+
else:
83+
try:
84+
data = response.json()
85+
except (ValueError, AttributeError):
86+
data = {}
87+
if not isinstance(data, dict):
88+
data = {}
89+
90+
return {
91+
"error": data.get("error", ""),
92+
"error_description": data.get("error_description", ""),
93+
}
7794

7895
@property
7996
def error(self):

0 commit comments

Comments
 (0)