Except ServerErrors and sleep a bit before retrying

This commit is contained in:
Lonami Exo 2017-09-30 18:51:25 +02:00
parent 76e5206acc
commit c9dff552b8

View File

@ -10,7 +10,7 @@ from time import sleep
from . import helpers as utils from . import helpers as utils
from .crypto import rsa, CdnDecrypter from .crypto import rsa, CdnDecrypter
from .errors import ( from .errors import (
RPCError, BrokenAuthKeyError, RPCError, BrokenAuthKeyError, ServerError,
FloodWaitError, FileMigrateError, TypeNotFoundError, FloodWaitError, FileMigrateError, TypeNotFoundError,
UnauthorizedError, PhoneMigrateError, NetworkMigrateError, UserMigrateError UnauthorizedError, PhoneMigrateError, NetworkMigrateError, UserMigrateError
) )
@ -496,6 +496,13 @@ class TelegramBareClient:
while self._user_connected and not self._reconnect(): while self._user_connected and not self._reconnect():
sleep(0.1) # Retry forever until we can send the request sleep(0.1) # Retry forever until we can send the request
except ServerError as e:
# Telegram is having some issues, sleep a tiny bit and retry
self._logger.debug(
'[ERROR] Telegram is having some internal issues', e
)
sleep(2)
except FloodWaitError: except FloodWaitError:
sender.disconnect() sender.disconnect()
self.disconnect() self.disconnect()