Page MenuHomeSoftware Heritage

D5668.id20252.diff
No OneTemporary

D5668.id20252.diff

diff --git a/swh/graph/client.py b/swh/graph/client.py
--- a/swh/graph/client.py
+++ b/swh/graph/client.py
@@ -15,6 +15,12 @@
return "An unexpected error occurred in the Graph backend: {}".format(self.args)
+class GraphArgumentException(Exception):
+ def __init__(self, *args, response):
+ super().__init__(*args)
+ self.response = response
+
+
class RemoteGraphClient(RPCClient):
"""Client to the Software Heritage Graph."""
@@ -30,6 +36,13 @@
def get_lines(self, endpoint, **kwargs):
yield from self.raw_verb_lines("get", endpoint, **kwargs)
+ def raise_for_status(self, response) -> None:
+ if response.status_code // 100 == 4:
+ raise GraphArgumentException(
+ response.content.decode("ascii"), response=response
+ )
+ super().raise_for_status(response)
+
# Web API endpoints
def stats(self):
diff --git a/swh/graph/tests/test_api_client.py b/swh/graph/tests/test_api_client.py
--- a/swh/graph/tests/test_api_client.py
+++ b/swh/graph/tests/test_api_client.py
@@ -2,6 +2,7 @@
from pytest import raises
from swh.core.api import RemoteException
+from swh.graph.client import GraphArgumentException
def test_stats(graph_client):
@@ -288,17 +289,17 @@
def test_param_validation(graph_client):
- with raises(RemoteException) as exc_info: # SWHID not found
+ with raises(GraphArgumentException) as exc_info: # SWHID not found
list(graph_client.leaves("swh:1:ori:fff0000000000000000000000000000000000021"))
assert exc_info.value.response.status_code == 404
- with raises(RemoteException) as exc_info: # malformed SWHID
+ with raises(GraphArgumentException) as exc_info: # malformed SWHID
list(
graph_client.neighbors("swh:1:ori:fff000000zzzzzz0000000000000000000000021")
)
assert exc_info.value.response.status_code == 400
- with raises(RemoteException) as exc_info: # malformed edge specificaiton
+ with raises(GraphArgumentException) as exc_info: # malformed edge specificaiton
list(
graph_client.visit_nodes(
"swh:1:dir:0000000000000000000000000000000000000016",
@@ -308,7 +309,7 @@
)
assert exc_info.value.response.status_code == 400
- with raises(RemoteException) as exc_info: # malformed direction
+ with raises(GraphArgumentException) as exc_info: # malformed direction
list(
graph_client.visit_nodes(
"swh:1:dir:0000000000000000000000000000000000000016",

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 3, 3:37 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223808

Event Timeline