summaryrefslogtreecommitdiff
path: root/wrappers/python/eduvpncommon/error.py
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-02-14 13:48:15 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 12:26:12 +0200
commit943fd5723cb4fd9a916b8baa6858c5895e8172cb (patch)
treefc9ebd50d0e467604e90de921e3856404462a87b /wrappers/python/eduvpncommon/error.py
parentc961faa8d7ba02e601586c3ce531b2329c7b258e (diff)
Python: Move error class to a separate file
Signed-off-by: jwijenbergh <jeroenwijenbergh@protonmail.com>
Diffstat (limited to 'wrappers/python/eduvpncommon/error.py')
-rw-r--r--wrappers/python/eduvpncommon/error.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/wrappers/python/eduvpncommon/error.py b/wrappers/python/eduvpncommon/error.py
new file mode 100644
index 0000000..2ec82e7
--- /dev/null
+++ b/wrappers/python/eduvpncommon/error.py
@@ -0,0 +1,16 @@
+from enum import Enum
+
+class GoError(Exception):
+ message_dict: dict
+ code: Enum | None
+
+ def __init__(self, err: Enum, messages: dict):
+ assert err
+ try:
+ self.code = err
+ except ValueError:
+ self.code = None
+ self.message_dict = messages
+
+ def __str__(self):
+ return self.message_dict[self.code] if self.code in self.message_dict else f"unknown error ({self.code})"