Commit 0b116cd9 authored by Titouan Soulard's avatar Titouan Soulard

erp5_jio_connector: properly handle errors

parent 7e2d3e96
......@@ -53,10 +53,18 @@ class JioApiConnector(XMLObject):
user_credentials = (self.getUserId(), self.getPassword())
r = requests.post(get_url, json=request_dict, auth=user_credentials)
if r.status_code not in [200, 201]:
return None
# Return response when status code is as expected
if r.status_code in [200, 201]:
return r.json()
return r.json()
# Try to get an error message by parsing JSON
result = None
try:
result = r.json()
except:
raise Exception("Error when sending to API ({}): API returned invalid JSON".format(r.status_code))
raise Exception("Error when sending to API ({}): {}".format(r.status_code, result["message"]))
def getFromApi(self, request_dict):
return self._sendToApi("/get", request_dict)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment