Skip to content

Commit

Permalink
Refactor exceptions (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniu authored Feb 12, 2023
1 parent 6cc1d3e commit b005dff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
28 changes: 1 addition & 27 deletions gios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
URL_STATION,
URL_STATIONS,
)
from .exceptions import ApiError, InvalidSensorsData, NoStationError
from .model import GiosSensors

_LOGGER: Final = logging.getLogger(__name__)
Expand Down Expand Up @@ -151,30 +152,3 @@ async def _async_get(self, url: str) -> Any:
raise ApiError(str(resp.status))
data = await resp.json()
return data


class ApiError(Exception):
"""Raised when GIOS API request ended in error."""

def __init__(self, status: str) -> None:
"""Initialize."""
super().__init__(status)
self.status = status


class InvalidSensorsData(Exception):
"""Raised when sensors data is invalid."""

def __init__(self, status: str) -> None:
"""Initialize."""
super().__init__(status)
self.status = status


class NoStationError(Exception):
"""Raised when no measuring station error."""

def __init__(self, status: str) -> None:
"""Initialize."""
super().__init__(status)
self.status = status
22 changes: 22 additions & 0 deletions gios/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""GIOS exceptions."""


class GiosError(Exception):
"""Base class for GIOS errors."""

def __init__(self, status: str) -> None:
"""Initialize."""
super().__init__(status)
self.status = status


class ApiError(GiosError):
"""Raised when GIOS API request ended in error."""


class InvalidSensorsData(GiosError):
"""Raised when sensors data is invalid."""


class NoStationError(GiosError):
"""Raised when no measuring station error."""
3 changes: 2 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ ignored-classes=_CountingAttr
expected-line-ending-format=LF

[EXCEPTIONS]
overgeneral-exceptions=BaseException,Exception
overgeneral-exceptions==builtins.BaseException,
builtins.Exception

0 comments on commit b005dff

Please sign in to comment.