Skip to content

Commit

Permalink
Modified exception handling so HTML is a default fallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Sep 30, 2023
1 parent edeb7be commit 7415455
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/xero/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ def __init__(self, response):
class XeroUnauthorized(XeroException):
# HTTP 401: Unauthorized
def __init__(self, response):
if response.headers["content-type"].startswith("text/html"):
payload = parse_qs(response.text)
self.errors = [payload["oauth_problem"][0]]
self.problem = self.errors[0]
super().__init__(response, payload["oauth_problem_advice"][0])
elif response.headers["content-type"].startswith("application/json"):
if response.headers["content-type"].startswith("application/json"):
data = json.loads(response.text)
msg = data.get("Detail", "")
self.errors = [msg.split(":")[0]]
self.problem = self.errors[0]
super().__init__(response, msg)
else:
payload = parse_qs(response.text)
self.errors = [payload["oauth_problem"][0]]
self.problem = self.errors[0]
super().__init__(response, payload["oauth_problem_advice"][0])


class XeroForbidden(XeroException):
Expand Down

0 comments on commit 7415455

Please sign in to comment.