Page MenuHomeSoftware Heritage

D2688.diff
No OneTemporary

D2688.diff

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
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2017 The Software Heritage developers
+# Copyright (C) 2015-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -7,7 +7,7 @@
from swh.model import hashutil
from ..objstorage import DEFAULT_CHUNK_SIZE, DEFAULT_LIMIT
-from ..exc import ObjNotFoundError, ObjStorageAPIError
+from ..exc import Error, ObjNotFoundError, ObjStorageAPIError
class RemoteObjStorage:
@@ -24,7 +24,10 @@
"""
def __init__(self, **kwargs):
- self._proxy = RPCClient(api_exception=ObjStorageAPIError, **kwargs)
+ self._proxy = RPCClient(
+ api_exception=ObjStorageAPIError,
+ reraise_exceptions=[ObjNotFoundError, Error],
+ **kwargs)
def check_config(self, *, check_write):
return self._proxy.post('check_config', {'check_write': check_write})
@@ -47,11 +50,7 @@
return self.add(content, obj_id, check_presence=False)
def get(self, obj_id):
- ret = self._proxy.post('content/get', {'obj_id': obj_id})
- if ret is None:
- raise ObjNotFoundError(obj_id)
- else:
- return ret
+ return self._proxy.post('content/get', {'obj_id': obj_id})
def get_batch(self, obj_ids):
return self._proxy.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
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2019 The Software Heritage developers
+# Copyright (C) 2015-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -18,7 +18,7 @@
from swh.model import hashutil
from swh.objstorage import get_objstorage
from swh.objstorage.objstorage import DEFAULT_LIMIT
-from swh.objstorage.exc import ObjNotFoundError
+from swh.objstorage.exc import Error, ObjNotFoundError
from swh.core.statsd import statsd
@@ -66,19 +66,13 @@
@timed
async def get_bytes(request):
req = await decode_request(request)
- try:
- ret = request.app['objstorage'].get(**req)
- except ObjNotFoundError:
- ret = {
- 'error': 'object_not_found',
- 'request': req,
- }
- return encode_data(ret, status=404)
- else:
- statsd.increment('swh_objstorage_out_bytes_total',
- len(ret),
- tags={'endpoint': 'get_bytes'})
- return encode_data(ret)
+
+ ret = request.app['objstorage'].get(**req)
+
+ statsd.increment('swh_objstorage_out_bytes_total',
+ len(ret),
+ tags={'endpoint': 'get_bytes'})
+ return encode_data(ret)
@timed
@@ -177,6 +171,8 @@
"""
client_max_size = config.get('client_max_size', 1024 * 1024 * 1024)
app = RPCServerApp(client_max_size=client_max_size)
+ app.client_exception_classes = (ObjNotFoundError, Error)
+
# retro compatibility configuration settings
app['config'] = config
_cfg = config['objstorage']

File Metadata

Mime Type
text/plain
Expires
Fri, Jun 20, 5:07 PM (2 w, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215786

Event Timeline