Skip to content

Commit

Permalink
localapi: add timeout exception
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  • Loading branch information
Noltari committed Aug 28, 2023
1 parent 1cb5a08 commit 444e58d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aioqsw/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class APIError(QswError):
"""Exception raised when API fails."""


class APITimeout(QswError):
"""Exception raised when API timeouts."""


class InternalServerError(APIError):
"""Exception raised when API returns internal server error."""

Expand Down
5 changes: 5 additions & 0 deletions aioqsw/localapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
)
from .exceptions import (
APIError,
APITimeout,
InternalServerError,
InvalidHost,
InvalidResponse,
Expand Down Expand Up @@ -117,6 +118,8 @@ async def http_request_bytes(
)
except ClientError as err:
raise InvalidHost(err) from err
except asyncio.TimeoutError as err:
raise APITimeout(err) from err

resp_bytes = await resp.read()

Expand Down Expand Up @@ -144,6 +147,8 @@ async def http_request(
)
except ClientError as err:
raise InvalidHost(err) from err
except asyncio.TimeoutError as err:
raise APITimeout(err) from err

resp_json = None
try:
Expand Down

0 comments on commit 444e58d

Please sign in to comment.