Skip to content

Commit

Permalink
New error types.
Browse files Browse the repository at this point in the history
  • Loading branch information
JrooTJunior committed May 10, 2018
1 parent 1f8b2b4 commit 3076173
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiogram/bot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ async def _check_result(method_name, response):
raise exceptions.NetworkError('File too large for uploading. '
'Check telegram api limits https://core.telegram.org/bots/api#senddocument')
elif response.status >= HTTPStatus.INTERNAL_SERVER_ERROR:
if 'restart' in description:
raise exceptions.RestartingTelegram()
raise exceptions.TelegramAPIError(description)
raise exceptions.TelegramAPIError(f"{description} [{response.status}]")

Expand Down
12 changes: 12 additions & 0 deletions aiogram/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
BadWebhook
WebhookRequireHTTPS
BadWebhookPort
BadWebhookAddrInfo
CantParseUrl
NotFound
MethodNotKnown
Expand All @@ -39,6 +40,7 @@
NetworkError
RetryAfter
MigrateToChat
RestartingTelegram
AIOGramWarning
TimeoutWarning
Expand Down Expand Up @@ -232,6 +234,11 @@ class BadWebhookPort(BadWebhook):
text = 'bad webhook: ' + match


class BadWebhookAddrInfo(BadWebhook):
match = 'getaddrinfo: Temporary failure in name resolution'
text = 'bad webhook: ' + match


class CantParseUrl(BadRequest):
match = 'can\'t parse URL'

Expand Down Expand Up @@ -282,6 +289,11 @@ class NetworkError(TelegramAPIError):
pass


class RestartingTelegram(TelegramAPIError):
def __init__(self):
super(RestartingTelegram, self).__init__('The Telegram Bot API service is restarting. Wait few second.')


class RetryAfter(TelegramAPIError):
def __init__(self, retry_after):
super(RetryAfter, self).__init__(f"Flood control exceeded. Retry in {retry_after} seconds.")
Expand Down

0 comments on commit 3076173

Please sign in to comment.