Adds handler for error responses

pull/18777/head
Jhonny Everson 10 years ago committed by Matt Clay
parent 4da34d198b
commit 7a10716ceb

@ -187,6 +187,9 @@ def _post_monitor(module, options):
msg = api.Monitor.create(type=module.params['type'], query=module.params['query'],
name=module.params['name'], message=module.params['message'],
options=options)
if 'errors' in msg:
module.fail_json(msg=str(msg['errors']))
else:
module.exit_json(changed=True, msg=msg)
except Exception, e:
module.fail_json(msg=str(e))
@ -197,7 +200,9 @@ def _update_monitor(module, monitor, options):
msg = api.Monitor.update(id=monitor['id'], query=module.params['query'],
name=module.params['name'], message=module.params['message'],
options=options)
if len(set(msg) - set(monitor)) == 0:
if 'errors' in msg:
module.fail_json(msg=str(msg['errors']))
elif len(set(msg) - set(monitor)) == 0:
module.exit_json(changed=False, msg=msg)
else:
module.exit_json(changed=True, msg=msg)

Loading…
Cancel
Save