Skip to content

Commit 4ca2c44

Browse files
almetRémy HUBSCHER
authored andcommitted
Better error message for create_collection.
1 parent 8c6adcb commit 4ca2c44

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

kinto_client/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,10 @@ def create_collection(self, collection=None, bucket=None,
224224
permissions=permissions,
225225
headers=headers)
226226
except KintoException as e:
227-
if e.reponse.status_code == 403:
227+
if e.response.status_code == 403:
228228
msg = "Unauthorized. Please check that the bucket exists."
229-
e.message = msg
229+
e = KintoException(msg, e)
230230
raise e
231-
232231
return resp
233232

234233
def update_collection(self, data=None, collection=None, bucket=None,

kinto_client/exceptions.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
class KintoException(Exception):
2-
pass
3-
4-
5-
class BucketNotFound(KintoException):
62
request = None
73
response = None
84

95
def __init__(self, message=None, exception=None):
10-
super(BucketNotFound, self).__init__(self, message)
6+
super(KintoException, self).__init__(self, message)
117
self.message = message
128
if exception is not None:
139
self.request = exception.request
1410
self.response = exception.response
11+
else:
12+
self.request = None
13+
self.response = None
14+
15+
16+
class BucketNotFound(KintoException):
17+
pass

kinto_client/tests/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@ def test_get_or_create_raise_in_other_cases(self):
406406
collection="coll",
407407
if_not_exists=True)
408408

409+
def test_create_collection_raises_a_special_error_on_403(self):
410+
self.session.request.side_effect = get_http_error(status=403)
411+
with self.assertRaises(KintoException) as e:
412+
self.client.create_collection(
413+
bucket="buck",
414+
collection="coll")
415+
expected_msg = "Unauthorized. Please check that the bucket exists."
416+
e.exception.message = expected_msg
417+
409418

410419
class RecordTest(unittest.TestCase):
411420
def setUp(self):

kinto_client/tests/test_endpoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ def test_missing_arguments_raise_an_error(self):
4747
with self.assertRaises(KintoException) as context:
4848
self.endpoints.get('record', bucket='buck', collection='coll')
4949
msg = "Cannot get record endpoint, id is missing"
50-
assert text_type(context.exception) == msg
50+
assert msg in text_type(context.exception)
5151

5252
def test_null_arguments_raise_an_error(self):
5353
# Include a null record id; it should raise an error.
5454
with self.assertRaises(KintoException) as context:
5555
self.endpoints.get('record', bucket='buck', collection='coll',
5656
id=None)
5757
msg = "Cannot get record endpoint, id is missing"
58-
assert text_type(context.exception) == msg
58+
assert msg in text_type(context.exception)
5959

6060
def test_arguments_are_slugified(self):
6161
assert self.endpoints.get('bucket', bucket='My Bucket') ==\

0 commit comments

Comments
 (0)