Skip to content

Commit a5761d9

Browse files
authored
Fix error with HTTP 204 response
2 parents 074bdb3 + d7e42e1 commit a5761d9

2 files changed

Lines changed: 46 additions & 15 deletions

File tree

docs/delete_sla.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# delete_sla
2+
3+
Delete an SLA from the Rubrik Cluster
4+
5+
```py
6+
def delete_sla(self, name, timeout=15):
7+
```
8+
9+
## Arguments
10+
11+
| Name | Type | Description | Choices |
12+
|-------------|------|-----------------------------------------------------------------------------|---------|
13+
| name | [type] | The name of the SLA you wish to delete. | |
14+
15+
## Keyword Arguments
16+
17+
| Name | Type | Description | Choices | Default |
18+
|-------------|------|-----------------------------------------------------------------------------|---------|---------|
19+
| timeout | int | The number of seconds to wait to establish a connection to the Rubrik cluster. | | 15 |
20+
21+
## Returns
22+
23+
| Type | Return Value |
24+
|------|-----------------------------------------------------------------------------------------------|
25+
| dict | The full API response for `DELETE /v1/sla_domain`. |
26+

rubrik_cdm/api.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)