Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7343002
D8228.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D8228.id.diff
View Options
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
@@ -77,6 +77,11 @@
objstorage = None
+@app.errorhandler(ObjNotFoundError)
+def not_found_error_handler(exception):
+ return error_handler(exception, encode_data, status_code=404)
+
+
@app.errorhandler(Error)
def argument_error_handler(exception):
return error_handler(exception, encode_data, status_code=400)
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
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2020 The Software Heritage developers
+# Copyright (C) 2015-2022 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
@@ -115,7 +115,7 @@
def test_check_missing(self):
content, obj_id = self.hash_content(b"check_missing")
- with self.assertRaises(exc.Error):
+ with self.assertRaises(exc.ObjNotFoundError):
self.storage.check(obj_id)
def test_check_present(self):
diff --git a/swh/objstorage/tests/test_objstorage_api.py b/swh/objstorage/tests/test_objstorage_api.py
--- a/swh/objstorage/tests/test_objstorage_api.py
+++ b/swh/objstorage/tests/test_objstorage_api.py
@@ -1,13 +1,15 @@
-# Copyright (C) 2015-2020 The Software Heritage developers
+# Copyright (C) 2015-2022 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
+from hashlib import sha1
import shutil
import tempfile
import unittest
import pytest
+import requests
from swh.core.api.tests.server_testing import ServerTestFixture
from swh.objstorage.api.server import app
@@ -38,6 +40,13 @@
super().tearDown()
shutil.rmtree(self.tmpdir)
+ def test_404_status_code_on_missing_object(self):
+ response = requests.post(
+ self.url() + "content/get",
+ json={"obj_id": sha1(b"missing").hexdigest()},
+ )
+ assert response.status_code == 404
+
@pytest.mark.skip("makes no sense to test this for the remote api")
def test_delete_not_allowed(self):
pass
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mar 17 2025, 6:39 PM (7 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217216
Attached To
D8228: api/server: Ensure to return a 404 status code for not found object
Event Timeline
Log In to Comment