Add support for signed error codes

This commit is contained in:
Dan 2021-04-12 09:14:50 +02:00
parent 0b0bec9e27
commit b6f97ee924
3 changed files with 23 additions and 6 deletions

View File

@ -40,4 +40,5 @@ UPLOAD_NO_VOLUME Telegram is having internal problems. Please try again later
VOLUME_LOC_NOT_FOUND Telegram is having internal problems. Please try again later VOLUME_LOC_NOT_FOUND Telegram is having internal problems. Please try again later
WORKER_BUSY_TOO_LONG_RETRY Server workers are too busy right now due to Telegram having internal problems. Please try again later WORKER_BUSY_TOO_LONG_RETRY Server workers are too busy right now due to Telegram having internal problems. Please try again later
WP_ID_GENERATE_FAILED Telegram is having internal problems. Please try again later WP_ID_GENERATE_FAILED Telegram is having internal problems. Please try again later
GROUPCALL_ADD_PARTICIPANTS_FAILED Failure while adding voice chat member due to Telegram having internal problems. Please try again later GROUPCALL_ADD_PARTICIPANTS_FAILED Failure while adding voice chat member due to Telegram having internal problems. Please try again later
No workers running The Telegram server is restarting its workers. Try again later.
1 id message
40 VOLUME_LOC_NOT_FOUND Telegram is having internal problems. Please try again later
41 WORKER_BUSY_TOO_LONG_RETRY Server workers are too busy right now due to Telegram having internal problems. Please try again later
42 WP_ID_GENERATE_FAILED Telegram is having internal problems. Please try again later
43 GROUPCALL_ADD_PARTICIPANTS_FAILED Failure while adding voice chat member due to Telegram having internal problems. Please try again later
44 No workers running The Telegram server is restarting its workers. Try again later.

View File

@ -0,0 +1,2 @@
id message
Timeout Telegram is having internal problems. Please try again later.
1 id message
2 Timeout Telegram is having internal problems. Please try again later.

View File

@ -32,8 +32,15 @@ class RPCError(Exception):
NAME = None NAME = None
MESSAGE = "{x}" MESSAGE = "{x}"
def __init__(self, x: Union[int, raw.types.RpcError] = None, rpc_name: str = None, is_unknown: bool = False): def __init__(
super().__init__("[{} {}]: {} {}".format( self,
x: Union[int, str, raw.types.RpcError] = None,
rpc_name: str = None,
is_unknown: bool = False,
is_signed: bool = False
):
super().__init__("[{}{} {}]: {} {}".format(
"-" if is_signed else "",
self.CODE, self.CODE,
self.ID or self.NAME, self.ID or self.NAME,
self.MESSAGE.format(x=x), self.MESSAGE.format(x=x),
@ -52,14 +59,19 @@ class RPCError(Exception):
@staticmethod @staticmethod
def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]): def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
error_code = rpc_error.error_code error_code = rpc_error.error_code
is_signed = error_code < 0
error_message = rpc_error.error_message error_message = rpc_error.error_message
rpc_name = ".".join(rpc_type.QUALNAME.split(".")[1:]) rpc_name = ".".join(rpc_type.QUALNAME.split(".")[1:])
if is_signed:
error_code = -error_code
if error_code not in exceptions: if error_code not in exceptions:
raise UnknownError( raise UnknownError(
x=f"[{error_code} {error_message}]", x=f"[{error_code} {error_message}]",
rpc_name=rpc_name, rpc_name=rpc_name,
is_unknown=True is_unknown=True,
is_signed=is_signed
) )
error_id = re.sub(r"_\d+", "_X", error_message) error_id = re.sub(r"_\d+", "_X", error_message)
@ -70,7 +82,8 @@ class RPCError(Exception):
exceptions[error_code]["_"] exceptions[error_code]["_"]
)(x=f"[{error_code} {error_message}]", )(x=f"[{error_code} {error_message}]",
rpc_name=rpc_name, rpc_name=rpc_name,
is_unknown=True) is_unknown=True,
is_signed=is_signed)
x = re.search(r"_(\d+)", error_message) x = re.search(r"_(\d+)", error_message)
x = x.group(1) if x is not None else x x = x.group(1) if x is not None else x
@ -80,7 +93,8 @@ class RPCError(Exception):
exceptions[error_code][error_id] exceptions[error_code][error_id]
)(x=x, )(x=x,
rpc_name=rpc_name, rpc_name=rpc_name,
is_unknown=False) is_unknown=False,
is_signed=is_signed)
class UnknownError(RPCError): class UnknownError(RPCError):