24 lines
707 B
Python
24 lines
707 B
Python
"""Глобальный обработчик ошибок."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from aiogram import Dispatcher
|
|
from aiogram.types import ErrorEvent
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def register_errors(dp: Dispatcher) -> None:
|
|
"""Зарегистрировать обработчик, чтобы одна ошибка не роняла поллинг."""
|
|
|
|
@dp.errors()
|
|
async def on_error(event: ErrorEvent) -> bool:
|
|
exc = event.exception
|
|
logger.error(
|
|
"Необработанная ошибка при обработке апдейта",
|
|
exc_info=(type(exc), exc, exc.__traceback__),
|
|
)
|
|
return True
|