fix: Better error handling in FrappeClient login
This commit is contained in:
parent
3db2754b6f
commit
79ff0eeaf8
1 changed files with 12 additions and 2 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue