mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Handle Telegram exceptions on start(). Fixes #121
The client doesn't need to be stopped as it never started successfully.
This commit is contained in:
parent
eb8513e009
commit
c75a4f182a
@ -216,28 +216,33 @@ class Client(Methods, BaseClient):
|
|||||||
self.session.start()
|
self.session.start()
|
||||||
self.is_started = True
|
self.is_started = True
|
||||||
|
|
||||||
if self.user_id is None:
|
try:
|
||||||
|
if self.user_id is None:
|
||||||
|
if self.token is None:
|
||||||
|
self.authorize_user()
|
||||||
|
else:
|
||||||
|
self.authorize_bot()
|
||||||
|
|
||||||
|
self.save_session()
|
||||||
|
|
||||||
if self.token is None:
|
if self.token is None:
|
||||||
self.authorize_user()
|
now = time.time()
|
||||||
|
|
||||||
|
if abs(now - self.date) > Client.OFFLINE_SLEEP:
|
||||||
|
self.peers_by_username = {}
|
||||||
|
self.peers_by_phone = {}
|
||||||
|
|
||||||
|
self.get_initial_dialogs()
|
||||||
|
self.get_contacts()
|
||||||
|
else:
|
||||||
|
self.send(functions.messages.GetPinnedDialogs())
|
||||||
|
self.get_initial_dialogs_chunk()
|
||||||
else:
|
else:
|
||||||
self.authorize_bot()
|
self.send(functions.updates.GetState())
|
||||||
|
except Exception as e:
|
||||||
self.save_session()
|
self.is_started = False
|
||||||
|
self.session.stop()
|
||||||
if self.token is None:
|
raise e
|
||||||
now = time.time()
|
|
||||||
|
|
||||||
if abs(now - self.date) > Client.OFFLINE_SLEEP:
|
|
||||||
self.peers_by_username = {}
|
|
||||||
self.peers_by_phone = {}
|
|
||||||
|
|
||||||
self.get_initial_dialogs()
|
|
||||||
self.get_contacts()
|
|
||||||
else:
|
|
||||||
self.send(functions.messages.GetPinnedDialogs())
|
|
||||||
self.get_initial_dialogs_chunk()
|
|
||||||
else:
|
|
||||||
self.send(functions.updates.GetState())
|
|
||||||
|
|
||||||
for i in range(self.UPDATES_WORKERS):
|
for i in range(self.UPDATES_WORKERS):
|
||||||
self.updates_workers_list.append(
|
self.updates_workers_list.append(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user