Skip to content

Commit

Permalink
Raise dedicated time out error (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede authored Feb 2, 2024
1 parent 44b060a commit df3bd36
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions aiotankerkoenig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .const import GasType, Sort, Status
from .exceptions import (
TankerkoenigConnectionError,
TankerkoenigConnectionTimeoutError,
TankerkoenigError,
TankerkoenigInvalidKeyError,
)
Expand All @@ -15,6 +16,7 @@
"TankerkoenigError",
"TankerkoenigConnectionError",
"TankerkoenigInvalidKeyError",
"TankerkoenigConnectionTimeoutError",
"GasType",
"Sort",
"Status",
Expand Down
5 changes: 3 additions & 2 deletions aiotankerkoenig/aiotankerkoenig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from yarl import URL

from .const import GasType, Sort
from .exceptions import TankerkoenigConnectionError, TankerkoenigError
from .exceptions import TankerkoenigConnectionTimeoutError, TankerkoenigError
from .models import (
PriceInfo,
PriceInfoResponse,
Expand Down Expand Up @@ -60,9 +60,10 @@ async def _request(self, path: str, params: dict[str, Any]) -> str:
url,
headers=headers,
)
response.raise_for_status()
except asyncio.TimeoutError as exception:
msg = "Timeout occurred while connecting to tankerkoenig.de API"
raise TankerkoenigConnectionError(
raise TankerkoenigConnectionTimeoutError(
msg,
) from exception

Expand Down
4 changes: 4 additions & 0 deletions aiotankerkoenig/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ class TankerkoenigConnectionError(TankerkoenigError):
"""Raised when a connection error occurs."""


class TankerkoenigConnectionTimeoutError(TankerkoenigConnectionError):
"""Raised when a connection times out."""


class TankerkoenigInvalidKeyError(TankerkoenigError):
"""Raised when the API key is invalid."""
4 changes: 2 additions & 2 deletions tests/test_aiotankerkoenig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
GasType,
Sort,
Tankerkoenig,
TankerkoenigConnectionError,
TankerkoenigConnectionTimeoutError,
TankerkoenigError,
TankerkoenigInvalidKeyError,
)
Expand All @@ -38,7 +38,7 @@ async def response_handler(_: str, **_kwargs: Any) -> CallbackResult:
api_key="abc123",
request_timeout=1,
) as tankerkoenig_client:
with pytest.raises(TankerkoenigConnectionError):
with pytest.raises(TankerkoenigConnectionTimeoutError):
await tankerkoenig_client.station_details(station_id="1")


Expand Down

0 comments on commit df3bd36

Please sign in to comment.