mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-17 15:50:10 -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:
parent
dbab3fd1fe
commit
47765d21e4
@ -67,16 +67,10 @@ class APIError(Exception):
|
||||
class NotLoggedInError(APIError):
|
||||
"""The session is not valid or expired."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class NotConnectedError(APIError):
|
||||
"""The service can't contact the specified device."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class TokenError(APIError):
|
||||
"""An authentication token was rejected."""
|
||||
@ -90,16 +84,10 @@ class FailedRequestError(APIError):
|
||||
device.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidRequestError(APIError):
|
||||
"""The server rejected a request as invalid."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class MonitorError(APIError):
|
||||
"""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.
|
||||
if 'returnCd' in out:
|
||||
code = out['returnCd']
|
||||
if code == '0000':
|
||||
pass
|
||||
elif code in API_ERRORS:
|
||||
raise API_ERRORS[code]()
|
||||
else:
|
||||
if code != '0000':
|
||||
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user