mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
jira: log error messages in "errors" key (#311)
Jira's API can return a empty "errorMessages" list, and the real error is in the "errors" object. This happens, for example, if a user tries to file a ticket in a project that does not exist (tested with Jira v7.13.8) Check both "errorMessages" and "errors", and report both values with fail_json(). Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
parent
f5ed0689c1
commit
041824b98e
2 changed files with 12 additions and 3 deletions
2
changelogs/fragments/311-jira-error-handling.yaml
Normal file
2
changelogs/fragments/311-jira-error-handling.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- jira - improve error message handling (https://github.com/ansible-collections/community.general/pull/311).
|
|
@ -286,7 +286,7 @@ import sys
|
||||||
|
|
||||||
from ansible.module_utils.six.moves.urllib.request import pathname2url
|
from ansible.module_utils.six.moves.urllib.request import pathname2url
|
||||||
|
|
||||||
from ansible.module_utils._text import to_text, to_bytes
|
from ansible.module_utils._text import to_text, to_bytes, to_native
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.urls import fetch_url
|
||||||
|
@ -311,10 +311,17 @@ def request(url, user, passwd, timeout, data=None, method=None):
|
||||||
if info['status'] not in (200, 201, 204):
|
if info['status'] not in (200, 201, 204):
|
||||||
error = json.loads(info['body'])
|
error = json.loads(info['body'])
|
||||||
if error:
|
if error:
|
||||||
module.fail_json(msg=error['errorMessages'])
|
msg = []
|
||||||
|
for key in ('errorMessages', 'errors'):
|
||||||
|
if error.get(key):
|
||||||
|
msg.append(error[key])
|
||||||
|
if msg:
|
||||||
|
module.fail_json(msg=to_native(', '.join(msg)))
|
||||||
|
else:
|
||||||
|
module.fail_json(msg=to_native(error))
|
||||||
else:
|
else:
|
||||||
# Fallback print body, if it cant be decoded
|
# Fallback print body, if it cant be decoded
|
||||||
module.fail_json(msg=info['body'])
|
module.fail_json(msg=to_native(info['body']))
|
||||||
|
|
||||||
body = response.read()
|
body = response.read()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue