From 1ecdb7061bc60f880a1061263770964a662ae09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gr=C3=BCner?= Date: Thu, 23 Jun 2016 22:15:55 +0200 Subject: [PATCH] cloudflare_dns: Improve error handling (#2470) Use the new "body" field of the info dict in case of a HTTPError. --- .../modules/extras/network/cloudflare_dns.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/extras/network/cloudflare_dns.py b/lib/ansible/modules/extras/network/cloudflare_dns.py index 238e7dff98b..e98c7cd48b5 100644 --- a/lib/ansible/modules/extras/network/cloudflare_dns.py +++ b/lib/ansible/modules/extras/network/cloudflare_dns.py @@ -349,11 +349,17 @@ class CloudflareAPI(object): result = None try: content = resp.read() - result = json.loads(content) except AttributeError: - error_msg += "; The API response was empty" - except json.JSONDecodeError: - error_msg += "; Failed to parse API response: {0}".format(content) + if info['body']: + content = info['body'] + else: + error_msg += "; The API response was empty" + + if content: + try: + result = json.loads(content) + except json.JSONDecodeError: + error_msg += "; Failed to parse API response: {0}".format(content) # received an error status but no data with details on what failed if (info['status'] not in [200,304]) and (result is None):