From 58ebd3bc0f00c532e97e9a5571471ffab87934ba Mon Sep 17 00:00:00 2001 From: AL-LCL Date: Fri, 19 May 2023 10:39:49 +0200 Subject: GOD-VIEW --- client/error.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 client/error.py (limited to 'client/error.py') 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 -- cgit v1.2.3