summaryrefslogtreecommitdiff
path: root/client/error.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/error.py')
-rw-r--r--client/error.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/client/error.py b/client/error.py
new file mode 100644
index 0000000..2956271
--- /dev/null
+++ b/client/error.py
@@ -0,0 +1,72 @@
+'''
+ Error handling client decorators, to provide
+ useful information sent back to the server or
+ handle critical errors accordingly.
+
+ Verified: 2020 December 30 & 2021 February 6
+ * Follows PEP8
+ * Tested Platforms
+ * Windows 10
+'''
+
+from client.state import ClientStatic
+from shared.helper import Helper
+from shared.state import Static
+from shared.data import Data
+
+import sys
+
+if Static.EXE:
+ from client.helper import ClientHelper
+
+ import time
+
+
+class ReconnectError(Exception):
+ pass
+
+
+class ClientError:
+
+ if Static.EXE:
+ __RECONNECT_TIMER = 10
+
+ @staticmethod
+ def general(callback):
+ def wrapper(*args, **kwargs):
+ try:
+ return callback(*args, **kwargs)
+ except Exception as error:
+ return Data.parse(Helper.join(
+ 'Client Side Execution Failed',
+ f'{type(error).__name__}: {error}'
+ ), status=Static.DANGER)
+
+ return wrapper
+
+ @staticmethod
+ def critical(callback):
+ def wrapper(*args, **kwargs):
+ try:
+ return callback(*args, **kwargs)
+ except SystemExit:
+ raise
+ except ReconnectError:
+ if Static.EXE:
+ ClientHelper.restart()
+ else:
+ sys.exit()
+ except TimeoutError:
+ if Static.EXE:
+ time.sleep(ClientError.__RECONNECT_TIMER)
+ ClientHelper.restart()
+ else:
+ sys.exit()
+ except Exception:
+ if Static.EXE and ClientStatic.STICKY:
+ time.sleep(ClientError.__RECONNECT_TIMER)
+ ClientHelper.restart()
+ else:
+ sys.exit()
+
+ return wrapper