File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,13 @@ def get_bucket(self, bucket=None):
255
255
try :
256
256
resp , _ = self .session .request ('get' , endpoint )
257
257
except KintoException as e :
258
+ error_resp_code = e .response .status_code
259
+ if error_resp_code == 401 :
260
+ msg = ("Unauthorized. Please authenticate or make sure the bucket "
261
+ "can be read anonymously." )
262
+ e = KintoException (msg , e )
263
+ raise e
264
+
258
265
raise BucketNotFound (bucket or self ._bucket_name , e )
259
266
return resp
260
267
Original file line number Diff line number Diff line change @@ -285,6 +285,23 @@ def test_unexisting_bucket_raises(self):
285
285
self .assertEquals (e .request , mock .sentinel .request )
286
286
self .assertEquals (e .message , 'test' )
287
287
288
+ def test_unauthorized_raises_a_kinto_exception (self ):
289
+ # Make the next call to sess.request raise a 401.
290
+ exception = KintoException ()
291
+ exception .response = mock .MagicMock ()
292
+ exception .response .status_code = 401
293
+ exception .request = mock .sentinel .request
294
+ self .session .request .side_effect = exception
295
+
296
+ with self .assertRaises (KintoException ) as cm :
297
+ self .client .get_bucket ('test' )
298
+ e = cm .exception
299
+ self .assertEquals (e .response , exception .response )
300
+ self .assertEquals (e .request , mock .sentinel .request )
301
+ self .assertEquals (e .message ,
302
+ "Unauthorized. Please authenticate or make sure the bucket "
303
+ "can be read anonymously." )
304
+
288
305
def test_http_500_raises_an_error (self ):
289
306
exception = KintoException ()
290
307
exception .response = mock .MagicMock ()
You can’t perform that action at this time.
0 commit comments