Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from .replykeyboardmarkup import ReplyKeyboardMarkup
from .replykeyboardremove import ReplyKeyboardRemove, ReplyKeyboardHide
from .forcereply import ForceReply
from .error import TelegramError
from .error import TelegramError, StopPropagation
from .inputfile import InputFile
from .file import File
from .emoji import Emoji
Expand Down Expand Up @@ -118,7 +118,7 @@
'InputLocationMessageContent', 'InputMessageContent', 'InputTextMessageContent',
'InputVenueMessageContent', 'KeyboardButton', 'Location', 'Message', 'MessageEntity',
'ParseMode', 'PhotoSize', 'ReplyKeyboardRemove', 'ReplyKeyboardMarkup', 'ReplyMarkup',
'Sticker', 'TelegramError', 'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue',
'Sticker', 'TelegramError', 'StopPropagation', 'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue',
'Video', 'Voice', 'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'WebhookInfo', 'Animation',
Expand Down
4 changes: 4 additions & 0 deletions telegram/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ def __init__(self, retry_after):
super(RetryAfter,
self).__init__('Flood control exceeded. Retry in {} seconds'.format(retry_after))
self.retry_after = float(retry_after)


class StopPropagation(Exception):
pass
46 changes: 26 additions & 20 deletions telegram/ext/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from future.builtins import range

from telegram import TelegramError
from telegram import TelegramError, StopPropagation
from telegram.ext.handler import Handler
from telegram.utils.promise import Promise

Expand Down Expand Up @@ -259,29 +259,35 @@ def process_update(self, update):

else:
for group in self.groups:
for handler in self.handlers[group]:
try:
if handler.check_update(update):
handler.handle_update(update, self)
break
# Dispatch any errors
except TelegramError as te:
self.logger.warn('A TelegramError was raised while processing the '
'Update.')

try:
for handler in self.handlers[group]:
try:
self.dispatch_error(update, te)
if handler.check_update(update):
handler.handle_update(update, self)
break
except StopPropagation as e:
raise e
# Dispatch any errors
except TelegramError as te:
self.logger.warn('A TelegramError was raised while processing the '
'Update.')

try:
self.dispatch_error(update, te)
except Exception:
self.logger.exception('An uncaught error was raised while '
'handling the error')
finally:
break

# Errors should not stop the thread
except Exception:
self.logger.exception('An uncaught error was raised while '
'handling the error')
finally:
'processing the update')
break

# Errors should not stop the thread
except Exception:
self.logger.exception('An uncaught error was raised while '
'processing the update')
break
except StopPropagation:
self.logger.debug('Handler has stopped handling chain')
break

def add_handler(self, handler, group=DEFAULT_GROUP):
"""
Expand Down