Add support for signed error codes
This commit is contained in:
parent
0b0bec9e27
commit
b6f97ee924
@ -41,3 +41,4 @@ VOLUME_LOC_NOT_FOUND Telegram is having internal problems. Please try again late
|
|||||||
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.
|
|
2
compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
Normal file
2
compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
id message
|
||||||
|
Timeout Telegram is having internal problems. Please try again later.
|
|
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user