1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #1761 from coder2020official/master

Extended exception handler behaviour for async
This commit is contained in:
Badiboy 2022-11-06 09:23:02 +03:00 committed by GitHub
commit 2dad99ad95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -354,7 +354,7 @@ class AsyncTeleBot:
while self._polling: while self._polling:
try: try:
await self._process_polling(non_stop=False, timeout=timeout, request_timeout=request_timeout, await self._process_polling(non_stop=True, timeout=timeout, request_timeout=request_timeout,
allowed_updates=allowed_updates, *args, **kwargs) allowed_updates=allowed_updates, *args, **kwargs)
except Exception as e: except Exception as e:
if logger_level and logger_level >= logging.ERROR: if logger_level and logger_level >= logging.ERROR:
@ -421,20 +421,34 @@ class AsyncTeleBot:
continue continue
else: else:
return return
except asyncio_helper.ApiTelegramException as e: except asyncio_helper.ApiException as e:
logger.error(str(e)) handled = False
if non_stop: if self.exception_handler:
self.exception_handler.handle(e)
handled = True
if not handled:
logger.error('Unhandled exception (full traceback for debug level): %s', str(e))
logger.debug(traceback.format_exc())
if non_stop or handled:
continue continue
else: else:
break break
except Exception as e: except Exception as e:
logger.error('Cause exception while getting updates.') handled = False
if non_stop: if self.exception_handler:
logger.error(str(e)) self.exception_handler.handle(e)
await asyncio.sleep(3) handled = True
if not handled:
logger.error('Unhandled exception (full traceback for debug level): %s', str(e))
logger.debug(traceback.format_exc())
if non_stop or handled:
continue continue
else: else:
raise e break
finally: finally:
self._polling = False self._polling = False
await self.close_session() await self.close_session()