Skip to content

Commit

Permalink
fix(parse-errors): ensure if block execution (#1854)
Browse files Browse the repository at this point in the history
When error messages contains more than one object,
ensure that they are all parsed.
  • Loading branch information
kmosti authored Aug 30, 2024
1 parent 84071a4 commit 196194a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jira/resilientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def parse_errors(resp: Response) -> list[str]:
if "message" in resp_data:
# Jira 5.1 errors
parsed_errors = [resp_data["message"]]
elif "errorMessage" in resp_data:
if "errorMessage" in resp_data:
# Sometimes Jira returns `errorMessage` as a message error key
# for example for the "Service temporary unavailable" error
parsed_errors = [resp_data["errorMessage"]]
elif "errorMessages" in resp_data:
if "errorMessages" in resp_data:
# Jira 5.0.x error messages sometimes come wrapped in this array
# Sometimes this is present but empty
error_messages = resp_data["errorMessages"]
Expand All @@ -118,7 +118,7 @@ def parse_errors(resp: Response) -> list[str]:
parsed_errors = list(error_messages)
else:
parsed_errors = [error_messages]
elif "errors" in resp_data:
if "errors" in resp_data:
resp_errors = resp_data["errors"]
if len(resp_errors) > 0 and isinstance(resp_errors, dict):
# Catching only 'errors' that are dict. See https://github.com/pycontribs/jira/issues/350
Expand Down
6 changes: 6 additions & 0 deletions tests/test_resilientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def test_status_codes_retries(
(500, {}, '{"errorMessages": "err1"}', ["err1"]),
(500, {}, '{"errorMessages": ["err1", "err2"]}', ["err1", "err2"]),
(500, {}, '{"errors": {"code1": "err1", "code2": "err2"}}', ["err1", "err2"]),
(
500,
{},
'{"errorMessages": [], "errors": {"code1": "err1", "code2": "err2"}}',
["err1", "err2"],
),
]


Expand Down

0 comments on commit 196194a

Please sign in to comment.