File tree 1 file changed +26
-0
lines changed
atlassian/bitbucket/cloud
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
from ..base import BitbucketBase
4
4
5
+ from requests import HTTPError
6
+
5
7
6
8
class BitbucketCloudBase (BitbucketBase ):
7
9
def __init__ (self , url , * args , ** kwargs ):
@@ -84,3 +86,27 @@ def _get_paged(
84
86
trailing = False
85
87
86
88
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