diff options
Diffstat (limited to 'ansible_collections/community/zabbix/plugins/httpapi/zabbix.py')
-rw-r--r-- | ansible_collections/community/zabbix/plugins/httpapi/zabbix.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/ansible_collections/community/zabbix/plugins/httpapi/zabbix.py b/ansible_collections/community/zabbix/plugins/httpapi/zabbix.py index 3db65532c..56ba0356d 100644 --- a/ansible_collections/community/zabbix/plugins/httpapi/zabbix.py +++ b/ansible_collections/community/zabbix/plugins/httpapi/zabbix.py @@ -165,12 +165,16 @@ class HttpApi(HttpApiBase): try: json_data = json.loads(value) if value else {} - if "result" in json_data: - json_data = json_data["result"] # JSONDecodeError only available on Python 3.5+ except ValueError: raise ConnectionError("Invalid JSON response: %s" % value) + if "error" in json_data: + raise ConnectionError("REST API returned %s when sending %s" % (json_data["error"], data)) + + if "result" in json_data: + json_data = json_data["result"] + try: # Some methods return bool not a dict in "result" iter(json_data) @@ -178,9 +182,6 @@ class HttpApi(HttpApiBase): # Do not try to find "error" if it is not a dict return response.getcode(), json_data - if "error" in json_data: - raise ConnectionError("REST API returned %s when sending %s" % (json_data["error"], data)) - return response.getcode(), json_data except AnsibleConnectionFailure as e: self.connection.queue_message("vvv", "AnsibleConnectionFailure: %s" % e) |