From 572f103db7c8f3a7e1408379e37814ba4620d2b0 Mon Sep 17 00:00:00 2001 From: coder2020official Date: Sat, 22 Oct 2022 21:48:29 +0400 Subject: [PATCH] Extended exception handler behaviour for async --- telebot/async_telebot.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 3a9e142..d18bce9 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -421,17 +421,30 @@ class AsyncTeleBot: continue else: return - except asyncio_helper.ApiTelegramException as e: - logger.error(str(e)) - if non_stop: + except asyncio_helper.ApiException as e: + handled = False + if self.exception_handler: + self.exception_handler.handle(e) + handled = True + + if not handled: + logger.debug(traceback.format_exc()) + + if non_stop or handled: continue else: - break + raise e except Exception as e: - logger.error('Cause exception while getting updates.') - if non_stop: - logger.error(str(e)) - await asyncio.sleep(3) + handled = False + if self.exception_handler: + self.exception_handler.handle(e) + handled = True + + if not handled: + logger.error('Cause exception while getting updates. Enable debug logging for more info.') + logger.debug(traceback.format_exc()) + + if non_stop or handled: continue else: raise e