From 7415455777320fc94ad00b567d1e784338efdd92 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 30 Sep 2023 10:14:33 +0800 Subject: [PATCH] Modified exception handling so HTML is a default fallback. --- src/xero/exceptions.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/xero/exceptions.py b/src/xero/exceptions.py index ad09b08..1e7cebc 100644 --- a/src/xero/exceptions.py +++ b/src/xero/exceptions.py @@ -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):