File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1
1
# coding=utf-8
2
2
import logging
3
3
4
+ from requests import HTTPError
5
+
4
6
from .rest_client import AtlassianRestAPI
5
7
6
8
log = logging .getLogger (__name__ )
@@ -909,3 +911,22 @@ def create_request_type(
909
911
910
912
url = "rest/servicedeskapi/servicedesk/{}/requesttype" .format (service_desk_id )
911
913
return self .post (url , headers = self .experimental_headers , data = data )
914
+
915
+ def raise_for_status (self , response ):
916
+ """
917
+ Checks the response for an error status and raises an exception with the error message provided by the server
918
+ :param response:
919
+ :return:
920
+ """
921
+ if response .status_code == 401 and response .headers .get ("Content-Type" ) != "application/json;charset=UTF-8" :
922
+ raise HTTPError ("Unauthorized (401)" , response = response )
923
+
924
+ if 400 <= response .status_code < 600 :
925
+ try :
926
+ j = response .json ()
927
+ error_msg = j ["errorMessage" ]
928
+ except Exception as e :
929
+ log .error (e )
930
+ response .raise_for_status ()
931
+ else :
932
+ raise HTTPError (error_msg , response = response )
You can’t perform that action at this time.
0 commit comments