Skip to content

Commit

Permalink
feat: setup exception hierarchy (#199)
Browse files Browse the repository at this point in the history
* feat: setup exception hierarchy

* fix: improve ActionTimeoutException message

* refactor: move APIException in _exceptions module

* chore: typo

Co-authored-by: Julian Tölle <julian.toelle97@gmail.com>

* chore: wording

Co-authored-by: Julian Tölle <julian.toelle97@gmail.com>

---------

Co-authored-by: Julian Tölle <julian.toelle97@gmail.com>
  • Loading branch information
jooola and apricote authored Jun 21, 2023
1 parent 03089f9 commit 8466645
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
6 changes: 6 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ API Clients
Exceptions
---------------

.. autoclass:: hcloud.HCloudException
:members:

.. autoclass:: hcloud.APIException
:members:

.. autoclass:: hcloud.actions.domain.ActionException
:members:

.. autoclass:: hcloud.actions.domain.ActionFailedException
:members:

Expand Down
3 changes: 2 additions & 1 deletion hcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .hcloud import APIException, Client # noqa
from ._exceptions import APIException, HCloudException # noqa
from .hcloud import Client # noqa
14 changes: 14 additions & 0 deletions hcloud/_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class HCloudException(Exception):
"""There was an error while using the hcloud library"""


class APIException(HCloudException):
"""There was an error while performing an API Request"""

def __init__(self, code, message, details):
self.code = code
self.message = message
self.details = details

def __str__(self):
return self.message
15 changes: 9 additions & 6 deletions hcloud/actions/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from hcloud.core.domain import BaseDomain

from .._exceptions import HCloudException


class Action(BaseDomain):
"""Action Domain
Expand Down Expand Up @@ -56,15 +58,16 @@ def __init__(
self.error = error


class ActionFailedException(Exception):
"""The Action you was waiting for failed"""
class ActionException(HCloudException):
"""A generic action exception"""

def __init__(self, action):
self.action = action


class ActionTimeoutException(Exception):
"""The Action you was waiting for timeouted in hcloud-python."""
class ActionFailedException(ActionException):
"""The Action you were waiting for failed"""

def __init__(self, action):
self.action = action

class ActionTimeoutException(ActionException):
"""The Action you were waiting for timed out"""
13 changes: 1 addition & 12 deletions hcloud/hcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,7 @@
from hcloud.volumes.client import VolumesClient

from .__version__ import VERSION


class APIException(Exception):
"""There was an error while performing an API Request"""

def __init__(self, code, message, details):
self.code = code
self.message = message
self.details = details

def __str__(self):
return self.message
from ._exceptions import APIException


class Client:
Expand Down

0 comments on commit 8466645

Please sign in to comment.