File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
atlassian/bitbucket/cloud Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 22
33from ..base import BitbucketBase
44
5+ from requests import HTTPError
6+
57
68class 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 ()
You can’t perform that action at this time.
0 commit comments