Skip to content

Commit 588897e

Browse files
authored
Bitbucket Cloud: provide custom raise_for_status (atlassian-api#925)
The default one in AtlassianRestAPI does not work for Bitbucket Cloud. Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
1 parent 947a1b5 commit 588897e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

atlassian/bitbucket/cloud/base.py

+26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from ..base import BitbucketBase
44

5+
from requests import HTTPError
6+
57

68
class BitbucketCloudBase(BitbucketBase):
79
def __init__(self, url, *args, **kwargs):
@@ -84,3 +86,27 @@ def _get_paged(
8486
trailing = False
8587

8688
return
89+
90+
def raise_for_status(self, response):
91+
"""
92+
Checks the response for errors and throws an exception if return code >= 400
93+
94+
Implementation for Bitbucket Cloud according to
95+
https://developer.atlassian.com/cloud/bitbucket/rest/intro/#standardized-error-responses
96+
97+
:param response:
98+
:return:
99+
"""
100+
if 400 <= response.status_code < 600:
101+
try:
102+
j = response.json()
103+
e = j["error"]
104+
error_msg = e["message"]
105+
if e.get("detail"):
106+
error_msg += "\n" + e["detail"]
107+
except Exception:
108+
response.raise_for_status()
109+
else:
110+
raise HTTPError(error_msg, response=response)
111+
else:
112+
response.raise_for_status()

0 commit comments

Comments
 (0)