@@ -136,17 +136,19 @@ def _common_api(self, call_type, api_version, api_endpoint, config=None, job_sta
136136
137137 self .log (str (api_request ) + "\n " )
138138 try :
139- api_response = api_request .json ()
140- # Check to see if an error message has been provided by Rubrik
141- for key , value in api_response .items ():
142- if key == "errorType" or key == 'message' :
143- error_message = api_response ['message' ]
144- api_request .raise_for_status ()
145-
146- # Check for GQL error message in the data response
147- if key == "error" :
148- error_message = api_response ['error' ]
149- api_request .raise_for_status ()
139+ # request.json() will fail on a 204 (No Content) so skip the response check
140+ if api_request .status_code != 204 :
141+ api_response = api_request .json ()
142+ # Check to see if an error message has been provided by Rubrik
143+ for key , value in api_response .items ():
144+ if key == "errorType" or key == 'message' :
145+ error_message = api_response ['message' ]
146+ api_request .raise_for_status ()
147+
148+ # Check for GQL error message in the data response
149+ if key == "error" :
150+ error_message = api_response ['error' ]
151+ api_request .raise_for_status ()
150152
151153 except BaseException :
152154 api_request .raise_for_status ()
@@ -182,16 +184,19 @@ def _common_api(self, call_type, api_version, api_endpoint, config=None, job_sta
182184 if call_type == "QUERY" :
183185 try :
184186 error_message
185- raise BaseException
187+ raise APICallException ( error_message )
186188 except NameError :
187189 try :
188190 return api_request .json ()["data" ]
189191 except BaseException :
190192 pass
191-
192- return api_request .json ()
193+
194+ # request.json() will fail on a 204 (No Content), so just the response code
195+ if api_request .status_code != 204 :
196+ return api_request .json ()
197+ else :
198+ return {'status_code' : api_request .status_code }
193199 except BaseException :
194- raise APICallException (error_message )
195200 return {'status_code' : api_request .status_code }
196201
197202 def get (self , api_version , api_endpoint , timeout = 15 , authentication = True , params = None ):
0 commit comments