diff --git a/src/bot/__init__.py b/src/bot/__init__.py index 4631e4f..f256bcf 100644 --- a/src/bot/__init__.py +++ b/src/bot/__init__.py @@ -3,13 +3,13 @@ import functools from sqlalchemy.future import Engine from telebot.async_telebot import AsyncTeleBot -from . import callback_handlers, message_handlers +from . import callback_handlers, exception_handler, message_handlers -__all__ = ["callback_handlers", "message_handlers"] +__all__ = ["callback_handlers", "exception_handler", "message_handlers"] def create_bot(token: str, engine: Engine) -> AsyncTeleBot: - bot = AsyncTeleBot(token) + bot = AsyncTeleBot(token, exception_handler=exception_handler.Handler) bot.register_message_handler( functools.partial(message_handlers.set_master_password, bot, engine), commands=["set_master_pass"], diff --git a/src/bot/exception_handler.py b/src/bot/exception_handler.py new file mode 100644 index 0000000..a348db8 --- /dev/null +++ b/src/bot/exception_handler.py @@ -0,0 +1,8 @@ +import traceback +from typing import Type + + +class Handler: + @staticmethod + def handle(exc: Type[BaseException]) -> None: + traceback.print_exception(exc)