Fix cloudflare_dns JSON response error handling (#42894)

* The JSONDecodeError exception only exists in Python 3.

* Without a properly parsed JSON response there is no more error
  processing to be done, no matter the http response code.

Relates to #38178
pull/42006/merge
Andreas Olsson 6 years ago committed by Abhijeet Kasurde
parent 4e489d1be8
commit c6854fde29

@ -354,11 +354,11 @@ class CloudflareAPI(object):
if content:
try:
result = json.loads(to_text(content, errors='surrogate_or_strict'))
except (json.JSONDecodeError, UnicodeError) as e:
except (getattr(json, 'JSONDecodeError', ValueError)) as e:
error_msg += "; Failed to parse API response with error {0}: {1}".format(to_native(e), content)
# received an error status but no data with details on what failed
if (info['status'] not in [200, 304]) and (result is None):
# Without a valid/parsed JSON response no more error processing can be done
if result is None:
self.module.fail_json(msg=error_msg)
if not result['success']:

Loading…
Cancel
Save