Skip to content

Commit be0d631

Browse files
committed
Fixing liter error
1 parent 92de1b0 commit be0d631

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

arangoasync/connection.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from arangoasync.auth import Auth, JwtToken
1313
from arangoasync.compression import CompressionManager, DefaultCompressionManager
1414
from arangoasync.exceptions import (
15+
AuthHeaderError,
16+
ClientConnectionAbortedError,
1517
ClientConnectionError,
16-
ConnectionAbortedError,
1718
JWTRefreshError,
1819
ServerConnectionError,
1920
)
@@ -102,7 +103,7 @@ async def process_request(self, request: Request) -> Response:
102103
self._host_resolver.change_host()
103104
host_index = self._host_resolver.get_host_index()
104105

105-
raise ConnectionAbortedError(
106+
raise ClientConnectionAbortedError(
106107
f"Can't connect to host(s) within limit ({self._host_resolver.max_tries})"
107108
)
108109

@@ -226,6 +227,27 @@ def __init__(
226227
if self._token is None and self._auth is None:
227228
raise ValueError("Either token or auth must be provided.")
228229

230+
@property
231+
def token(self) -> Optional[JwtToken]:
232+
"""Get the JWT token.
233+
234+
Returns:
235+
JwtToken | None: JWT token.
236+
"""
237+
return self._token
238+
239+
@token.setter
240+
def token(self, token: Optional[JwtToken]) -> None:
241+
"""Set the JWT token.
242+
243+
Args:
244+
token (JwtToken | None): JWT token.
245+
Setting it to None will cause the token to be automatically
246+
refreshed on the next request, if auth information is provided.
247+
"""
248+
self._token = token
249+
self._auth_header = f"bearer {self._token.token}" if self._token else None
250+
229251
async def refresh_token(self) -> None:
230252
"""Refresh the JWT token.
231253
@@ -248,7 +270,7 @@ async def refresh_token(self) -> None:
248270

249271
try:
250272
resp = await self.process_request(request)
251-
except ConnectionAbortedError as e:
273+
except ClientConnectionAbortedError as e:
252274
raise JWTRefreshError(str(e)) from e
253275
except ServerConnectionError as e:
254276
raise JWTRefreshError(str(e)) from e
@@ -267,27 +289,6 @@ async def refresh_token(self) -> None:
267289
"Failed to refresh the JWT token: got an expired token"
268290
) from e
269291

270-
@property
271-
def token(self) -> Optional[JwtToken]:
272-
"""Get the JWT token.
273-
274-
Returns:
275-
JwtToken | None: JWT token.
276-
"""
277-
return self._token
278-
279-
@token.setter
280-
def token(self, token: Optional[JwtToken]) -> None:
281-
"""Set the JWT token.
282-
283-
Args:
284-
token (JwtToken | None): JWT token.
285-
Setting it to None will cause the token to be automatically
286-
refreshed on the next request, if auth information is provided.
287-
"""
288-
self._token = token
289-
self._auth_header = f"bearer {self._token.token}" if self._token else None
290-
291292
async def send_request(self, request: Request) -> Response:
292293
"""Send an HTTP request to the ArangoDB server.
293294
@@ -303,6 +304,10 @@ async def send_request(self, request: Request) -> Response:
303304
"""
304305
if self._auth_header is None:
305306
await self.refresh_token()
307+
308+
if self._auth_header is None:
309+
raise AuthHeaderError("Failed to generate authorization header.")
310+
306311
request.headers["authorization"] = self._auth_header
307312

308313
try:

arangoasync/exceptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ def __init__(
6868
self.http_headers = resp.headers
6969

7070

71-
class ConnectionAbortedError(ArangoClientError):
71+
class ClientConnectionAbortedError(ArangoClientError):
7272
"""The connection was aborted."""
7373

7474

7575
class ClientConnectionError(ArangoClientError):
7676
"""The request was unable to reach the server."""
7777

7878

79+
class AuthHeaderError(ArangoClientError):
80+
"""The authentication header could not be determined."""
81+
82+
7983
class JWTExpiredError(ArangoClientError):
8084
"""JWT token has expired."""
8185

tests/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from arangoasync.compression import AcceptEncoding, DefaultCompressionManager
77
from arangoasync.connection import BasicConnection, JwtConnection
88
from arangoasync.exceptions import (
9+
ClientConnectionAbortedError,
910
ClientConnectionError,
10-
ConnectionAbortedError,
1111
ServerConnectionError,
1212
)
1313
from arangoasync.http import AioHTTPClient
@@ -128,7 +128,7 @@ async def mock_send_request(*args, **kwargs):
128128
auth=Auth(username=root, password=password),
129129
)
130130

131-
with pytest.raises(ConnectionAbortedError):
131+
with pytest.raises(ClientConnectionAbortedError):
132132
await connection.process_request(request)
133133

134134

0 commit comments

Comments
 (0)