1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

jira: cast error messages to strings (#707)

Sometimes Jira returns dicts as "errors" instead of simple strings.
For example, when a user specifies a field that cannot be set, Jira
returns a dict with the field name as a key and the error message as the
value.

In the rare case that we have both a "errorMessages" list and an
"errors" dict, when we combine those values later with join(), Python
raises a TypeError.

Transform each individual error message into a string, and then join()
the list of strings.
This commit is contained in:
Ken Dreyer 2020-07-29 15:38:51 -06:00 committed by GitHub
parent 9822d8172b
commit b29af922eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- jira - improve error message handling with multiple errors (https://github.com/ansible-collections/community.general/pull/707).

View file

@ -314,9 +314,9 @@ def request(url, user, passwd, timeout, data=None, method=None):
msg = []
for key in ('errorMessages', 'errors'):
if error.get(key):
msg.append(error[key])
msg.append(to_native(error[key]))
if msg:
module.fail_json(msg=to_native(', '.join(msg)))
module.fail_json(msg=', '.join(msg))
else:
module.fail_json(msg=to_native(error))
else: