Errors

Handling errors

Is recommended way that you should use errors inside handlers using try-except block, but in common cases you can use global errors handler at router or dispatcher level.

If you specify errors handler for router - it will be used for all handlers inside this router.

If you specify errors handler for dispatcher - it will be used for all handlers inside all routers.

@router.error(ExceptionTypeFilter(MyCustomException), F.update.message.as_("message"))
async def handle_my_custom_exception(event: ErrorEvent, message: Message):
    # do something with error
    await message.answer("Oops, something went wrong!")


@router.error()
async def error_handler(event: ErrorEvent):
    logger.critical("Critical error caused by %s", event.exception, exc_info=True)
    # do something with error
    ...

ErrorEvent

class litegram.types.error_event.ErrorEvent(*, update: Update, exception: Exception, **extra_data: Any)[исходный код]

Internal event, should be used to receive errors while processing Updates from Telegram

Source: https://core.telegram.org/bots/api#error-event

update: Update

Received update

exception: Exception

Exception

Error types

exception litegram.exceptions.LitegramError[исходный код]

Base exception for all litegram errors.

exception litegram.exceptions.DetailedLitegramError(message: str)[исходный код]

Base exception for all litegram errors with detailed message.

exception litegram.exceptions.CallbackAnswerException[исходный код]

Exception for callback answer.

exception litegram.exceptions.SceneException[исходный код]

Exception for scenes.

exception litegram.exceptions.UnsupportedKeywordArgument(message: str)[исходный код]

Exception raised when a keyword argument is passed as filter.

exception litegram.exceptions.TelegramAPIError(method: TelegramMethod[TelegramType], message: str)[исходный код]

Base exception for all Telegram API errors.

exception litegram.exceptions.TelegramNetworkError(method: TelegramMethod[TelegramType], message: str)[исходный код]

Base exception for all Telegram network errors.

exception litegram.exceptions.TelegramRetryAfter(method: TelegramMethod[TelegramType], message: str, retry_after: int)[исходный код]

Exception raised when flood control exceeds.

exception litegram.exceptions.TelegramMigrateToChat(method: TelegramMethod[TelegramType], message: str, migrate_to_chat_id: int)[исходный код]

Exception raised when chat has been migrated to a supergroup.

exception litegram.exceptions.TelegramBadRequest(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when request is malformed.

exception litegram.exceptions.TelegramNotFound(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when chat, message, user, etc. not found.

exception litegram.exceptions.TelegramConflictError(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when bot token is already used by another application in polling mode.

exception litegram.exceptions.TelegramUnauthorizedError(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when bot token is invalid.

exception litegram.exceptions.TelegramForbiddenError(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when bot is kicked from chat or etc.

exception litegram.exceptions.TelegramServerError(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when Telegram server returns 5xx error.

exception litegram.exceptions.RestartingTelegram(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when Telegram server is restarting.

It seems like this error is not used by Telegram anymore, but it’s still here for backward compatibility.

Currently, you should expect that Telegram can raise RetryAfter (with timeout 5 seconds)

error instead of this one.

exception litegram.exceptions.TelegramEntityTooLarge(method: TelegramMethod[TelegramType], message: str)[исходный код]

Exception raised when you are trying to send a file that is too large.

exception litegram.exceptions.ClientDecodeError(message: str, original: Exception, data: Any)[исходный код]

Exception raised when client can’t decode response. (Malformed response, etc.)

exception litegram.exceptions.DataNotDictLikeError(message: str)[исходный код]

Exception raised when data is not dict-like.