From 72a7dd5a5f2cf1bbd145f8d41ca6e545dda4e853 Mon Sep 17 00:00:00 2001 From: Davte Date: Thu, 15 Aug 2019 11:35:24 +0200 Subject: [PATCH] Catch and return unexpected exceptions during API calls --- davtelepot/__init__.py | 2 +- davtelepot/api.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index d2808ec..8e76e7d 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.2.7" +__version__ = "2.2.8" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/api.py b/davtelepot/api.py index 19f6a2a..6e168fb 100644 --- a/davtelepot/api.py +++ b/davtelepot/api.py @@ -298,12 +298,15 @@ class TelegramBot(object): "request" ) self.set_flood_wait(flood_wait) - return e + response_object = e except Exception as e: logging.error(f"{e}", exc_info=True) - return e + response_object = e except asyncio.TimeoutError as e: logging.info(f"{e}: {method} API call timed out") + except Exception as e: + logging.info(f"Unexpected eception:\n{e}") + response_object = e finally: if session_must_be_closed and not session.closed: await session.close()