Skip to content

Commit

Permalink
Log http exception (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
MelleD committed Sep 10, 2024
1 parent bdb4100 commit 2ffe6e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion custom_components/radar_warnings/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
"""Exceptions for radar_warnings."""
from .const import LOGGER

class RadarWarningConnectionError(Exception):
"""RadarWarning connection exception."""
"""RadarWarning connection exception."""

def __init__(self, message, status_code=None, details=None):
super().__init__(message)
self.message = message
self.status_code = status_code
self.details = details
LOGGER.error(self.__str__())

def __str__(self):
if self.status_code:
return f"{self.message} (Status code: {self.status_code}, Details: {self.details})"
return self.message
4 changes: 2 additions & 2 deletions custom_components/radar_warnings/radar_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def get_adress(self, point: Point, street: str | None) -> tuple[str | None
if response.status // 100 in [4, 5]:
contents = await response.read()
response.close()
raise RadarWarningConnectionError(
raise RadarWarningConnectionError("HTTP error occurred",
response.status, json.loads(contents.decode("utf8"))
)

Expand Down Expand Up @@ -162,7 +162,7 @@ async def get_pois(self):
if response.status // 100 in [4, 5]:
contents = await response.read()
response.close()
raise RadarWarningConnectionError(
raise RadarWarningConnectionError("HTTP error occurred",
response.status, json.loads(contents.decode("utf8"))
)

Expand Down

0 comments on commit 2ffe6e9

Please sign in to comment.