diff --git a/swh/objstorage/api/client.py b/swh/objstorage/api/client.py --- a/swh/objstorage/api/client.py +++ b/swh/objstorage/api/client.py @@ -8,7 +8,7 @@ from swh.model import hashutil from ..objstorage import ObjStorage, DEFAULT_CHUNK_SIZE -from ..exc import ObjStorageAPIError +from ..exc import ObjNotFoundError, ObjStorageAPIError class RemoteObjStorage(ObjStorage, SWHRemoteAPI): @@ -37,7 +37,11 @@ 'check_presence': check_presence}) def get(self, obj_id): - return self.post('content/get', {'obj_id': obj_id}) + ret = self.post('content/get', {'obj_id': obj_id}) + if ret is None: + raise ObjNotFoundError(obj_id) + else: + return ret def get_batch(self, obj_ids): return self.post('content/get/batch', {'obj_ids': obj_ids}) diff --git a/swh/objstorage/api/server.py b/swh/objstorage/api/server.py --- a/swh/objstorage/api/server.py +++ b/swh/objstorage/api/server.py @@ -12,6 +12,7 @@ encode_data_server as encode_data) from swh.model import hashutil from swh.objstorage import get_objstorage +from swh.objstorage.exc import ObjNotFoundError DEFAULT_CONFIG_PATH = 'objstorage/server' @@ -51,7 +52,16 @@ @asyncio.coroutine def get_bytes(request): req = yield from decode_request(request) - return encode_data(request.app['objstorage'].get(**req)) + try: + ret = request.app['objstorage'].get(**req) + except ObjNotFoundError: + ret = { + 'error': 'object_not_found', + 'request': req, + } + return encode_data(ret, status=404) + else: + return encode_data(ret) @asyncio.coroutine diff --git a/swh/objstorage/cloud/objstorage_azure.py b/swh/objstorage/cloud/objstorage_azure.py --- a/swh/objstorage/cloud/objstorage_azure.py +++ b/swh/objstorage/cloud/objstorage_azure.py @@ -101,7 +101,7 @@ container_name=self.container_name, blob_name=hex_obj_id) except AzureMissingResourceHttpError: - raise ObjNotFoundError('Content %s not found!' % hex_obj_id) + raise ObjNotFoundError(obj_id) return gzip.decompress(blob.content) diff --git a/swh/objstorage/cloud/objstorage_cloud.py b/swh/objstorage/cloud/objstorage_cloud.py --- a/swh/objstorage/cloud/objstorage_cloud.py +++ b/swh/objstorage/cloud/objstorage_cloud.py @@ -139,7 +139,7 @@ try: return self.driver.get_object(self.container_name, hex_obj_id) except ObjectDoesNotExistError as e: - raise ObjNotFoundError(e.object_name) + raise ObjNotFoundError(obj_id) def _put_object(self, content, obj_id): """Create an object in the cloud storage. diff --git a/swh/objstorage/tests/objstorage_testing.py b/swh/objstorage/tests/objstorage_testing.py --- a/swh/objstorage/tests/objstorage_testing.py +++ b/swh/objstorage/tests/objstorage_testing.py @@ -90,9 +90,11 @@ @istest def get_missing(self): content, obj_id = self.hash_content(b'get_missing') - with self.assertRaises(exc.Error): + with self.assertRaises(exc.ObjNotFoundError) as e: self.storage.get(obj_id) + self.assertIn(obj_id, e.exception.args) + @istest def check_missing(self): content, obj_id = self.hash_content(b'check_missing')