From dd31dcab7005897fc7b19288707231947e49b2dc Mon Sep 17 00:00:00 2001 From: Kevin Breit Date: Mon, 2 Jul 2018 03:42:50 -0500 Subject: [PATCH] Meraki module utility request() has improved error reporting (#39838) * request() has improved error reporting - 5xx errors show same as before - 3xx and 4xx errors show error body * Print body for errors greater than 300, but less than 500 * Remove trailing whitespace --- lib/ansible/module_utils/network/meraki/meraki.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/network/meraki/meraki.py b/lib/ansible/module_utils/network/meraki/meraki.py index d86f668a6b6..09423ab3125 100644 --- a/lib/ansible/module_utils/network/meraki/meraki.py +++ b/lib/ansible/module_utils/network/meraki/meraki.py @@ -259,8 +259,11 @@ class MerakiModule(object): self.response = info['msg'] self.status = info['status'] - if self.status >= 300: + if self.status >= 500: self.fail_json(msg='Request failed for {url}: {status} - {msg}'.format(**info)) + elif self.status >= 300: + self.fail_json(msg='Request failed for {url}: {status} - {msg}'.format(**info), + body=json.loads(to_native(info['body']))) try: return json.loads(to_native(resp.read())) except: