Skip to content

Commit

Permalink
chore: add fallback on unknown state
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Oct 1, 2024
1 parent 62a52d2 commit e45ec98
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/bot/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from aiogram import Bot, F, types
from aiogram.dispatcher.event.bases import SkipHandler
from aiogram.filters import ExceptionTypeFilter
from aiogram.fsm.context import FSMContext
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.fsm.storage.redis import DefaultKeyBuilder, RedisStorage
from aiogram.types import ErrorEvent
from aiogram_dialog import setup_dialogs
from aiogram_dialog.api.exceptions import UnknownIntent
from aiogram_dialog import DialogManager, setup_dialogs
from aiogram_dialog.api.exceptions import UnknownIntent, UnknownState

from src.bot.dispatcher import CustomDispatcher
from src.bot.logging_ import logger
Expand Down Expand Up @@ -35,6 +37,14 @@ async def unknown_intent_handler(event: ErrorEvent, callback_query: types.Callba
await callback_query.answer("Unknown intent: Please, try to restart the action.")


@dp.error(ExceptionTypeFilter(UnknownState))
async def on_unknown_state(event: ErrorEvent, state: FSMContext, dialog_manager: DialogManager):
logger.warning("Messed up dialog: %s", event.exception)
await state.clear()
await dialog_manager.reset_stack()
raise SkipHandler()


from src.bot.routers.commands import router as commands_router # noqa: E402
from src.bot.routers.registration import router as registration_router # noqa: E402
from src.bot.routers.admin import router as admin_router # noqa: E402
Expand Down

0 comments on commit e45ec98

Please sign in to comment.