mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-18 00:00:17 -07:00
Exceptions for API errors
This commit is contained in:
parent
3e11db0f7b
commit
375ee62ce3
16
wideq.py
16
wideq.py
@ -12,6 +12,14 @@ SVC_CODE = 'SVC202'
|
|||||||
CLIENT_ID = 'LGAO221A02'
|
CLIENT_ID = 'LGAO221A02'
|
||||||
|
|
||||||
|
|
||||||
|
class APIError(Exception):
|
||||||
|
"""An error reported by the API."""
|
||||||
|
|
||||||
|
def __init__(self, code, message):
|
||||||
|
self.code = code
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
|
||||||
def lgedm_post(url, data=None, access_token=None, session_id=None):
|
def lgedm_post(url, data=None, access_token=None, session_id=None):
|
||||||
"""Make an HTTP request in the format used by the API servers.
|
"""Make an HTTP request in the format used by the API servers.
|
||||||
|
|
||||||
@ -35,7 +43,13 @@ def lgedm_post(url, data=None, access_token=None, session_id=None):
|
|||||||
headers['x-thinq-jsessionId'] = session_id
|
headers['x-thinq-jsessionId'] = session_id
|
||||||
|
|
||||||
res = requests.post(url, json={DATA_ROOT: data}, headers=headers)
|
res = requests.post(url, json={DATA_ROOT: data}, headers=headers)
|
||||||
return res.json()[DATA_ROOT]
|
out = res.json()[DATA_ROOT]
|
||||||
|
|
||||||
|
# Check for API errors.
|
||||||
|
if 'returnCd' in out:
|
||||||
|
raise APIError(int(out['returnCd']), out['returnMsg'])
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
def gateway_info():
|
def gateway_info():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user