Catch and return unexpected exceptions during API calls

This commit is contained in:
Davte 2019-08-15 11:35:24 +02:00
parent f525caa2e5
commit 72a7dd5a5f
2 changed files with 6 additions and 3 deletions

View File

@ -14,7 +14,7 @@ __author__ = "Davide Testa"
__email__ = "davide@davte.it" __email__ = "davide@davte.it"
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
__license__ = "GNU General Public License v3.0" __license__ = "GNU General Public License v3.0"
__version__ = "2.2.7" __version__ = "2.2.8"
__maintainer__ = "Davide Testa" __maintainer__ = "Davide Testa"
__contact__ = "t.me/davte" __contact__ = "t.me/davte"

View File

@ -298,12 +298,15 @@ class TelegramBot(object):
"request" "request"
) )
self.set_flood_wait(flood_wait) self.set_flood_wait(flood_wait)
return e response_object = e
except Exception as e: except Exception as e:
logging.error(f"{e}", exc_info=True) logging.error(f"{e}", exc_info=True)
return e response_object = e
except asyncio.TimeoutError as e: except asyncio.TimeoutError as e:
logging.info(f"{e}: {method} API call timed out") logging.info(f"{e}: {method} API call timed out")
except Exception as e:
logging.info(f"Unexpected eception:\n{e}")
response_object = e
finally: finally:
if session_must_be_closed and not session.closed: if session_must_be_closed and not session.closed:
await session.close() await session.close()