Skip to content

Commit 54350dc

Browse files
committed
Merge branch 'handle-503-timeout'
2 parents 3c81006 + 9a8bf9d commit 54350dc

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

compiler/errors/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def start():
9696

9797
sub_class = caml(re.sub(r"_X", "_", error_id))
9898
sub_class = re.sub(r"^2", "Two", sub_class)
99+
sub_class = re.sub(r" ", "", sub_class)
99100

100101
f_all.write(" \"{}\": \"{}\",\n".format(error_id, sub_class))
101102

compiler/errors/source/500_INTERNAL_SERVER_ERROR.tsv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ UPLOAD_NO_VOLUME Telegram is having internal problems. Please try again later
4040
VOLUME_LOC_NOT_FOUND Telegram is having internal problems. Please try again later
4141
WORKER_BUSY_TOO_LONG_RETRY Server workers are too busy right now due to Telegram having internal problems. Please try again later
4242
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
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.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id message
2+
Timeout Telegram is having internal problems. Please try again later.

pyrogram/errors/rpc_error.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ class RPCError(Exception):
3232
NAME = None
3333
MESSAGE = "{x}"
3434

35-
def __init__(self, x: Union[int, raw.types.RpcError] = None, rpc_name: str = None, is_unknown: bool = False):
36-
super().__init__("[{} {}]: {} {}".format(
35+
def __init__(
36+
self,
37+
x: Union[int, str, raw.types.RpcError] = None,
38+
rpc_name: str = None,
39+
is_unknown: bool = False,
40+
is_signed: bool = False
41+
):
42+
super().__init__("[{}{} {}]: {} {}".format(
43+
"-" if is_signed else "",
3744
self.CODE,
3845
self.ID or self.NAME,
3946
self.MESSAGE.format(x=x),
@@ -52,14 +59,19 @@ def __init__(self, x: Union[int, raw.types.RpcError] = None, rpc_name: str = Non
5259
@staticmethod
5360
def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
5461
error_code = rpc_error.error_code
62+
is_signed = error_code < 0
5563
error_message = rpc_error.error_message
5664
rpc_name = ".".join(rpc_type.QUALNAME.split(".")[1:])
5765

66+
if is_signed:
67+
error_code = -error_code
68+
5869
if error_code not in exceptions:
5970
raise UnknownError(
6071
x=f"[{error_code} {error_message}]",
6172
rpc_name=rpc_name,
62-
is_unknown=True
73+
is_unknown=True,
74+
is_signed=is_signed
6375
)
6476

6577
error_id = re.sub(r"_\d+", "_X", error_message)
@@ -70,7 +82,8 @@ def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
7082
exceptions[error_code]["_"]
7183
)(x=f"[{error_code} {error_message}]",
7284
rpc_name=rpc_name,
73-
is_unknown=True)
85+
is_unknown=True,
86+
is_signed=is_signed)
7487

7588
x = re.search(r"_(\d+)", error_message)
7689
x = x.group(1) if x is not None else x
@@ -80,7 +93,8 @@ def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
8093
exceptions[error_code][error_id]
8194
)(x=x,
8295
rpc_name=rpc_name,
83-
is_unknown=False)
96+
is_unknown=False,
97+
is_signed=is_signed)
8498

8599

86100
class UnknownError(RPCError):

pyrogram/session/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from pyrogram import raw
3030
from pyrogram.connection import Connection
3131
from pyrogram.crypto import mtproto
32-
from pyrogram.errors import RPCError, InternalServerError, AuthKeyDuplicated, FloodWait
32+
from pyrogram.errors import RPCError, InternalServerError, AuthKeyDuplicated, FloodWait, ServiceUnavailable
3333
from pyrogram.raw.all import layer
3434
from pyrogram.raw.core import TLObject, MsgContainer, Int, FutureSalt, FutureSalts
3535
from .internals import MsgId, MsgFactory
@@ -433,7 +433,7 @@ async def send(
433433
log.warning(f'[{self.client.session_name}] Sleeping for {amount}s (required by "{query}")')
434434

435435
await asyncio.sleep(amount)
436-
except (OSError, TimeoutError, InternalServerError) as e:
436+
except (OSError, TimeoutError, InternalServerError, ServiceUnavailable) as e:
437437
if retries == 0:
438438
raise e from None
439439

0 commit comments

Comments
 (0)