mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Dev 3.x i18n & improvements (#696)
* Added base code and make code improvements * Auto-exclude coverage for `if TYPE_CHECKING:` * Fixed current coverage * Cover I18n module * Update pipeline * Fixed annotations * Added docs * Move exceptions * Added tests for KeyboardBuilder and initial docs * Remove help generator (removed from sources tree, requires rewrite) * Added patch-notes #698, #699, #700, #701, #702, #703
This commit is contained in:
parent
5bd1162f57
commit
e4046095d7
223 changed files with 1909 additions and 1121 deletions
102
aiogram/exceptions.py
Normal file
102
aiogram/exceptions.py
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
from typing import Optional
|
||||
|
||||
from aiogram.methods import TelegramMethod
|
||||
from aiogram.methods.base import TelegramType
|
||||
|
||||
|
||||
class TelegramAPIError(Exception):
|
||||
url: Optional[str] = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
method: TelegramMethod[TelegramType],
|
||||
message: str,
|
||||
) -> None:
|
||||
self.method = method
|
||||
self.message = message
|
||||
|
||||
def render_description(self) -> str:
|
||||
return self.message
|
||||
|
||||
def __str__(self) -> str:
|
||||
message = [self.render_description()]
|
||||
if self.url:
|
||||
message.append(f"(background on this error at: {self.url})")
|
||||
return "\n".join(message)
|
||||
|
||||
|
||||
class TelegramNetworkError(TelegramAPIError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramRetryAfter(TelegramAPIError):
|
||||
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:
|
||||
super().__init__(method=method, message=message)
|
||||
self.retry_after = retry_after
|
||||
|
||||
def render_description(self) -> str:
|
||||
description = f"Flood control exceeded on method {type(self.method).__name__!r}"
|
||||
if chat_id := getattr(self.method, "chat_id", None):
|
||||
description += f" in chat {chat_id}"
|
||||
description += f". Retry in {self.retry_after} seconds."
|
||||
return description
|
||||
|
||||
|
||||
class TelegramMigrateToChat(TelegramAPIError):
|
||||
url = "https://core.telegram.org/bots/api#responseparameters"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
method: TelegramMethod[TelegramType],
|
||||
message: str,
|
||||
migrate_to_chat_id: int,
|
||||
) -> None:
|
||||
super().__init__(method=method, message=message)
|
||||
self.migrate_to_chat_id = migrate_to_chat_id
|
||||
|
||||
def render_description(self) -> str:
|
||||
description = (
|
||||
f"The group has been migrated to a supergroup with id {self.migrate_to_chat_id}"
|
||||
)
|
||||
if chat_id := getattr(self.method, "chat_id", None):
|
||||
description += f" from {chat_id}"
|
||||
return description
|
||||
|
||||
|
||||
class TelegramBadRequest(TelegramAPIError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramNotFound(TelegramAPIError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramConflictError(TelegramAPIError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramUnauthorizedError(TelegramAPIError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramForbiddenError(TelegramAPIError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramServerError(TelegramAPIError):
|
||||
pass
|
||||
|
||||
|
||||
class RestartingTelegram(TelegramServerError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramEntityTooLarge(TelegramNetworkError):
|
||||
url = "https://core.telegram.org/bots/api#sending-files"
|
||||
Loading…
Add table
Add a link
Reference in a new issue