Skip to content

Commit 4bb337a

Browse files
authored
Fix #1154: add safety checks to parse 400 error responses (#1171)
Since I don't know if the original code was supposed to support specific response bodies, I decided to keep the original behaviour and add safety checks for the responses that we receive from Jira in 400 responses.
1 parent 3b9605e commit 4bb337a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

atlassian/rest_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ def raise_for_status(self, response):
474474
error_msg = "\n".join([k + ": " + v for k, v in j.items()])
475475
else:
476476
error_msg = "\n".join(
477-
j.get("errorMessages", list()) + [k.get("message", "") for k in j.get("errors", dict())]
477+
j.get("errorMessages", list())
478+
+ [
479+
k.get("message", "") if isinstance(k, dict) else v
480+
for k, v in j.get("errors", dict()).items()
481+
]
478482
)
479483
except Exception as e:
480484
log.error(e)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
responses['{"fields": {"issuetype": "foo", "summary": "summary", "project": "project"}}'] = {
2+
"status_code": 400,
3+
"errorMessages": [],
4+
"errors": {"labels": "Field 'labels' cannot be set. It is not on the appropriate screen, or unknown."},
5+
}

tests/test_jira.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ def test_get_issue_comment_not_found(self):
4444
"""Get comment on issue by id, but not found"""
4545
with self.assertRaises(HTTPError):
4646
self.jira.epic_issues("BAR-11")
47+
48+
def test_post_issue_with_invalid_request(self):
49+
"""Post an issue but receive a 400 error response"""
50+
# with self.assertRaises(HTTPError):
51+
self.jira.create_issue(fields={"issuetype": "foo", "summary": "summary", "project": "project"})

0 commit comments

Comments
 (0)