Skip to content

Commit a8745e7

Browse files
committed
extract check response code
1 parent ccf082e commit a8745e7

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

jsonbox.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,19 @@ def read(self,
5555
url = self._get_url(box_id, collection_or_record, sort_by, skip, limit, query)
5656

5757
response = requests.get(url)
58-
if response.ok:
59-
json_data = response.json()
60-
return json_data
61-
else:
62-
return False
58+
return self._check_response(response)
6359

6460
def write(self, data, box_id, collection=None):
6561
url = self._get_url(box_id, collection)
6662

6763
response = requests.post(url, json=data)
68-
if response.ok:
69-
json_data = response.json()
70-
return json_data
71-
else:
72-
return False
64+
return self._check_response(response)
7365

7466
def update(self, data, box_id, record_id):
7567
url = self._get_url(box_id, record_id)
7668

7769
response = requests.put(url, json=data)
78-
if response.ok:
79-
json_data = response.json()
80-
return json_data
81-
else:
82-
return False
70+
return self._check_response(response)
8371

8472
def delete(self, box_id, record_ids):
8573
if isinstance(record_ids, list):
@@ -94,6 +82,9 @@ def _delete_one(self, box_id, record_id):
9482
url = self._get_url(box_id, record_id)
9583

9684
response = requests.delete(url)
85+
return self._check_response(response)
86+
87+
def _check_response(self, response):
9788
if response.ok:
9889
json_data = response.json()
9990
return json_data

0 commit comments

Comments
 (0)