summaryrefslogtreecommitdiffstats
path: root/telepot/loop.py
diff options
context:
space:
mode:
Diffstat (limited to 'telepot/loop.py')
-rw-r--r--telepot/loop.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/telepot/loop.py b/telepot/loop.py
index 4b1331b..ad13491 100644
--- a/telepot/loop.py
+++ b/telepot/loop.py
@@ -64,7 +64,10 @@ class GetUpdatesLoop(RunForeverAsThread):
# No sort. Trust server to give messages in correct order.
for update in result:
- self._update_handler(update)
+ try:
+ self._update_handler(update)
+ except exception.UpdateKeyError:
+ print(f"Update with id {update['update_id']} caused an error, skipping", file=sys.stderr)
offset = update['update_id'] + 1
except exception.BadHTTPResponse as e:
@@ -100,16 +103,19 @@ def _dictify27(data):
_dictify = _dictify3 if sys.version_info >= (3,) else _dictify27
def _extract_message(update):
- key = _find_first_key(update, ['message',
- 'edited_message',
- 'channel_post',
- 'edited_channel_post',
- 'callback_query',
- 'inline_query',
- 'chosen_inline_result',
- 'shipping_query',
- 'pre_checkout_query'])
- return key, update[key]
+ try:
+ key = _find_first_key(update, ['message',
+ 'edited_message',
+ 'channel_post',
+ 'edited_channel_post',
+ 'callback_query',
+ 'inline_query',
+ 'chosen_inline_result',
+ 'shipping_query',
+ 'pre_checkout_query'])
+ return key, update[key]
+ except KeyError as ex:
+ raise exception.UpdateKeyError from ex
def _infer_handler_function(bot, h):
if h is None: