From 79ff0eeaf8de7a3ec45471da4e88916b0739f2c7 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 13 May 2020 05:45:38 +0530 Subject: [PATCH] fix: Better error handling in FrappeClient login --- frappe/frappeclient.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frappe/frappeclient.py b/frappe/frappeclient.py index 8611c21720..919c334e51 100644 --- a/frappe/frappeclient.py +++ b/frappe/frappeclient.py @@ -15,6 +15,9 @@ class AuthError(Exception): class SiteExpiredError(Exception): pass +class SiteUnreachableError(Exception): + pass + class FrappeException(Exception): pass @@ -53,9 +56,16 @@ class FrappeClient(object): if r.status_code==200 and r.json().get('message') in ("Logged In", "No App"): return r.json() + elif r.status_code == 502: + raise SiteUnreachableError else: - if json.loads(r.text).get('exc_type') == "SiteExpiredError": - raise SiteExpiredError + try: + error = json.loads(r.text) + if error.get('exc_type') == "SiteExpiredError": + raise SiteExpiredError + except json.decoder.JSONDecodeError: + error = r.text + print(error) raise AuthError def setup_key_authentication_headers(self):