[docs]classAiogramError(Exception):""" Base exception for all aiogram errors. """
[docs]classDetailedAiogramError(AiogramError):""" Base exception for all aiogram errors with detailed message. """url:Optional[str]=Nonedef__init__(self,message:str)->None:self.message=messagedef__str__(self)->str:message=self.messageifself.url:message+=f"\n(background on this error at: {self.url})"returnmessagedef__repr__(self)->str:returnf"{type(self).__name__}('{self}')"
[docs]classCallbackAnswerException(AiogramError):""" Exception for callback answer. """
[docs]classSceneException(AiogramError):""" Exception for scenes. """
[docs]classUnsupportedKeywordArgument(DetailedAiogramError):""" Exception raised when a keyword argument is passed as filter. """url=docs_url("migration_2_to_3.html",fragment_="filtering-events")
[docs]classTelegramAPIError(DetailedAiogramError):""" Base exception for all Telegram API errors. """label:str="Telegram server says"def__init__(self,method:TelegramMethod[TelegramType],message:str,)->None:super().__init__(message=message)self.method=methoddef__str__(self)->str:original_message=super().__str__()returnf"{self.label} - {original_message}"
[docs]classTelegramNetworkError(TelegramAPIError):""" Base exception for all Telegram network errors. """label="HTTP Client says"
[docs]classTelegramRetryAfter(TelegramAPIError):""" Exception raised when flood control exceeds. """url="https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this"def__init__(self,method:TelegramMethod[TelegramType],message:str,retry_after:int,)->None:description=f"Flood control exceeded on method {type(method).__name__!r}"ifchat_id:=getattr(method,"chat_id",None):description+=f" in chat {chat_id}"description+=f". Retry in {retry_after} seconds."description+=f"\nOriginal description: {message}"super().__init__(method=method,message=description)self.retry_after=retry_after
[docs]classTelegramMigrateToChat(TelegramAPIError):""" Exception raised when chat has been migrated to a supergroup. """url="https://core.telegram.org/bots/api#responseparameters"def__init__(self,method:TelegramMethod[TelegramType],message:str,migrate_to_chat_id:int,)->None:description=f"The group has been migrated to a supergroup with id {migrate_to_chat_id}"ifchat_id:=getattr(method,"chat_id",None):description+=f" from {chat_id}"description+=f"\nOriginal description: {message}"super().__init__(method=method,message=message)self.migrate_to_chat_id=migrate_to_chat_id
[docs]classTelegramBadRequest(TelegramAPIError):""" Exception raised when request is malformed. """
[docs]classTelegramNotFound(TelegramAPIError):""" Exception raised when chat, message, user, etc. not found. """
[docs]classTelegramConflictError(TelegramAPIError):""" Exception raised when bot token is already used by another application in polling mode. """
[docs]classTelegramUnauthorizedError(TelegramAPIError):""" Exception raised when bot token is invalid. """
[docs]classTelegramForbiddenError(TelegramAPIError):""" Exception raised when bot is kicked from chat or etc. """
[docs]classTelegramServerError(TelegramAPIError):""" Exception raised when Telegram server returns 5xx error. """
[docs]classRestartingTelegram(TelegramServerError):""" 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. """
[docs]classTelegramEntityTooLarge(TelegramNetworkError):""" Exception raised when you are trying to send a file that is too large. """url="https://core.telegram.org/bots/api#sending-files"
[docs]classClientDecodeError(AiogramError):""" Exception raised when client can't decode response. (Malformed response, etc.) """def__init__(self,message:str,original:Exception,data:Any)->None:self.message=messageself.original=originalself.data=datadef__str__(self)->str:original_type=type(self.original)return(f"{self.message}\n"f"Caused from error: "f"{original_type.__module__}.{original_type.__name__}: {self.original}\n"f"Content: {self.data}")