mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-23 06:50:29 +01:00
forward related update to errorhandlers
This commit is contained in:
parent
1b79a57673
commit
f59efe0f4b
1 changed files with 9 additions and 6 deletions
|
@ -107,6 +107,8 @@ class Broadcaster:
|
||||||
self.logger.info('Broadcaster thread started')
|
self.logger.info('Broadcaster thread started')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
update = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Pop update from update queue.
|
# Pop update from update queue.
|
||||||
# Blocks if no updates are available.
|
# Blocks if no updates are available.
|
||||||
|
@ -119,7 +121,7 @@ class Broadcaster:
|
||||||
|
|
||||||
# Broadcast any errors
|
# Broadcast any errors
|
||||||
except TelegramError as te:
|
except TelegramError as te:
|
||||||
self.broadcastError(te)
|
self.broadcastError(update, te)
|
||||||
|
|
||||||
self.logger.info('Broadcaster thread stopped')
|
self.logger.info('Broadcaster thread stopped')
|
||||||
|
|
||||||
|
@ -157,7 +159,7 @@ class Broadcaster:
|
||||||
|
|
||||||
# An error happened while polling
|
# An error happened while polling
|
||||||
if isinstance(update, TelegramError):
|
if isinstance(update, TelegramError):
|
||||||
self.broadcastError(update)
|
self.broadcastError(None, update)
|
||||||
handled = True
|
handled = True
|
||||||
|
|
||||||
# Telegram update (regex)
|
# Telegram update (regex)
|
||||||
|
@ -178,7 +180,7 @@ class Broadcaster:
|
||||||
|
|
||||||
# Update not recognized
|
# Update not recognized
|
||||||
if not handled:
|
if not handled:
|
||||||
self.broadcastError(TelegramError(
|
self.broadcastError(update, TelegramError(
|
||||||
"Received update of unknown type %s" % type(update)))
|
"Received update of unknown type %s" % type(update)))
|
||||||
|
|
||||||
# Add Handlers
|
# Add Handlers
|
||||||
|
@ -498,7 +500,7 @@ class Broadcaster:
|
||||||
if isinstance(update, t):
|
if isinstance(update, t):
|
||||||
self.broadcastTo(self.type_handlers[t], update)
|
self.broadcastTo(self.type_handlers[t], update)
|
||||||
else:
|
else:
|
||||||
self.broadcastError(TelegramError(
|
self.broadcastError(update, TelegramError(
|
||||||
"Received update of unknown type %s" % type(update)))
|
"Received update of unknown type %s" % type(update)))
|
||||||
|
|
||||||
def broadcastTelegramMessage(self, update):
|
def broadcastTelegramMessage(self, update):
|
||||||
|
@ -512,16 +514,17 @@ class Broadcaster:
|
||||||
|
|
||||||
self.broadcastTo(self.telegram_message_handlers, update)
|
self.broadcastTo(self.telegram_message_handlers, update)
|
||||||
|
|
||||||
def broadcastError(self, error):
|
def broadcastError(self, update, error):
|
||||||
"""
|
"""
|
||||||
Broadcasts an error.
|
Broadcasts an error.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
update (any): The pdate that caused the error
|
||||||
error (telegram.TelegramError): The Telegram error that was raised.
|
error (telegram.TelegramError): The Telegram error that was raised.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for handler in self.error_handlers:
|
for handler in self.error_handlers:
|
||||||
handler(self.bot, error)
|
handler(self.bot, update, error)
|
||||||
|
|
||||||
def broadcastTo(self, handlers, update):
|
def broadcastTo(self, handlers, update):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue