Skip to content

fix: ServerConnectionError #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arango/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
JwtSuperuserConnection,
)
from arango.database import StandardDatabase
from arango.exceptions import ServerConnectionError
from arango.exceptions import ArangoClientError, ServerConnectionError
from arango.http import (
DEFAULT_REQUEST_TIMEOUT,
DefaultHTTPClient,
Expand Down Expand Up @@ -300,6 +300,6 @@ def db(
except ServerConnectionError as err:
raise err
except Exception as err:
raise ServerConnectionError(f"bad connection: {err}")
raise ArangoClientError(f"bad connection: {err}")

return StandardDatabase(connection)
8 changes: 6 additions & 2 deletions arango/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,13 @@ def ping(self) -> int:
request = Request(method="get", endpoint="/_api/collection")
resp = self.send_request(request)
if resp.status_code in {401, 403}:
raise ServerConnectionError("bad username/password or token is expired")
raise ServerConnectionError(
resp, request, "bad username/password or token is expired"
)
if not resp.is_success: # pragma: no cover
raise ServerConnectionError(resp.error_message or "bad server response")
raise ServerConnectionError(
resp, request, resp.error_message or "bad server response"
)
return resp.status_code

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion arango/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class PregelJobDeleteError(ArangoServerError):
#####################


class ServerConnectionError(ArangoClientError):
class ServerConnectionError(ArangoServerError):
"""Failed to connect to ArangoDB server."""


Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from arango.client import ArangoClient
from arango.database import StandardDatabase
from arango.exceptions import ServerConnectionError
from arango.exceptions import ArangoClientError, ServerConnectionError
from arango.http import DefaultHTTPClient, DeflateRequestCompression
from arango.resolver import FallbackHostResolver, RandomHostResolver, SingleHostResolver
from tests.helpers import (
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_client_bad_connection(db, username, password, cluster):

# Test connection with invalid host URL
client = ArangoClient(hosts="http://127.0.0.1:8500")
with pytest.raises(ServerConnectionError) as err:
with pytest.raises(ArangoClientError) as err:
client.db(db.name, username, password, verify=True)
assert "bad connection" in str(err.value)

Expand Down
Loading