Skip to content

Commit 8466645

Browse files
jooolaapricote
andauthored
feat: setup exception hierarchy (#199)
* 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>
1 parent 03089f9 commit 8466645

5 files changed

Lines changed: 32 additions & 19 deletions

File tree

docs/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ API Clients
1919
Exceptions
2020
---------------
2121

22+
.. autoclass:: hcloud.HCloudException
23+
:members:
24+
2225
.. autoclass:: hcloud.APIException
2326
:members:
2427

28+
.. autoclass:: hcloud.actions.domain.ActionException
29+
:members:
30+
2531
.. autoclass:: hcloud.actions.domain.ActionFailedException
2632
:members:
2733

hcloud/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from .hcloud import APIException, Client # noqa
1+
from ._exceptions import APIException, HCloudException # noqa
2+
from .hcloud import Client # noqa

hcloud/_exceptions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class HCloudException(Exception):
2+
"""There was an error while using the hcloud library"""
3+
4+
5+
class APIException(HCloudException):
6+
"""There was an error while performing an API Request"""
7+
8+
def __init__(self, code, message, details):
9+
self.code = code
10+
self.message = message
11+
self.details = details
12+
13+
def __str__(self):
14+
return self.message

hcloud/actions/domain.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from hcloud.core.domain import BaseDomain
44

5+
from .._exceptions import HCloudException
6+
57

68
class Action(BaseDomain):
79
"""Action Domain
@@ -56,15 +58,16 @@ def __init__(
5658
self.error = error
5759

5860

59-
class ActionFailedException(Exception):
60-
"""The Action you was waiting for failed"""
61+
class ActionException(HCloudException):
62+
"""A generic action exception"""
6163

6264
def __init__(self, action):
6365
self.action = action
6466

6567

66-
class ActionTimeoutException(Exception):
67-
"""The Action you was waiting for timeouted in hcloud-python."""
68+
class ActionFailedException(ActionException):
69+
"""The Action you were waiting for failed"""
6870

69-
def __init__(self, action):
70-
self.action = action
71+
72+
class ActionTimeoutException(ActionException):
73+
"""The Action you were waiting for timed out"""

hcloud/hcloud.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,7 @@
2121
from hcloud.volumes.client import VolumesClient
2222

2323
from .__version__ import VERSION
24-
25-
26-
class APIException(Exception):
27-
"""There was an error while performing an API Request"""
28-
29-
def __init__(self, code, message, details):
30-
self.code = code
31-
self.message = message
32-
self.details = details
33-
34-
def __str__(self):
35-
return self.message
24+
from ._exceptions import APIException
3625

3726

3827
class Client:

0 commit comments

Comments
 (0)