1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-18 00:00:17 -07:00

Preserve codes for named errors

This simplifies the definition of error classes *and* preserves more
information about the underlying message from the API.
This commit is contained in:
Adrian Sampson 2019-12-26 13:35:53 -05:00
parent dbab3fd1fe
commit 47765d21e4

View File

@ -67,16 +67,10 @@ class APIError(Exception):
class NotLoggedInError(APIError): class NotLoggedInError(APIError):
"""The session is not valid or expired.""" """The session is not valid or expired."""
def __init__(self):
pass
class NotConnectedError(APIError): class NotConnectedError(APIError):
"""The service can't contact the specified device.""" """The service can't contact the specified device."""
def __init__(self):
pass
class TokenError(APIError): class TokenError(APIError):
"""An authentication token was rejected.""" """An authentication token was rejected."""
@ -90,16 +84,10 @@ class FailedRequestError(APIError):
device. device.
""" """
def __init__(self):
pass
class InvalidRequestError(APIError): class InvalidRequestError(APIError):
"""The server rejected a request as invalid.""" """The server rejected a request as invalid."""
def __init__(self):
pass
class MonitorError(APIError): class MonitorError(APIError):
"""Monitoring a device failed, possibly because the monitoring """Monitoring a device failed, possibly because the monitoring
@ -147,13 +135,12 @@ def lgedm_post(url, data=None, access_token=None, session_id=None):
# Check for API errors. # Check for API errors.
if 'returnCd' in out: if 'returnCd' in out:
code = out['returnCd'] code = out['returnCd']
if code == '0000': if code != '0000':
pass
elif code in API_ERRORS:
raise API_ERRORS[code]()
else:
message = out['returnMsg'] message = out['returnMsg']
raise APIError(code, message) if code in API_ERRORS:
raise API_ERRORS[code](code, message)
else:
raise APIError(code, message)
return out return out