mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
More API Exceptions.
This commit is contained in:
parent
77867fe109
commit
c0fcaa6f45
2 changed files with 18 additions and 0 deletions
|
|
@ -60,6 +60,7 @@ async def _check_result(method_name, response):
|
||||||
|
|
||||||
description = result_json.get('description') or body
|
description = result_json.get('description') or body
|
||||||
|
|
||||||
|
# TODO: refactor the detection of error types
|
||||||
if HTTPStatus.OK <= response.status <= HTTPStatus.IM_USED:
|
if HTTPStatus.OK <= response.status <= HTTPStatus.IM_USED:
|
||||||
return result_json.get('result')
|
return result_json.get('result')
|
||||||
elif 'retry_after' in result_json:
|
elif 'retry_after' in result_json:
|
||||||
|
|
@ -93,6 +94,8 @@ async def _check_result(method_name, response):
|
||||||
exceptions.CantParseUrl.throw()
|
exceptions.CantParseUrl.throw()
|
||||||
elif exceptions.PhotoAsInputFileRequired.check(description):
|
elif exceptions.PhotoAsInputFileRequired.check(description):
|
||||||
exceptions.PhotoAsInputFileRequired.throw()
|
exceptions.PhotoAsInputFileRequired.throw()
|
||||||
|
elif exceptions.ToMuchMessages.check(description):
|
||||||
|
exceptions.ToMuchMessages.throw()
|
||||||
raise exceptions.BadRequest(description)
|
raise exceptions.BadRequest(description)
|
||||||
elif response.status == HTTPStatus.NOT_FOUND:
|
elif response.status == HTTPStatus.NOT_FOUND:
|
||||||
if exceptions.MethodNotKnown.check(description):
|
if exceptions.MethodNotKnown.check(description):
|
||||||
|
|
@ -111,6 +114,8 @@ async def _check_result(method_name, response):
|
||||||
exceptions.BotBlocked.throw()
|
exceptions.BotBlocked.throw()
|
||||||
elif exceptions.UserDeactivated.check(description):
|
elif exceptions.UserDeactivated.check(description):
|
||||||
exceptions.UserDeactivated.throw()
|
exceptions.UserDeactivated.throw()
|
||||||
|
elif exceptions.CantInitiateConversation.check(description):
|
||||||
|
exceptions.UserDeactivated.throw()
|
||||||
raise exceptions.Unauthorized(description)
|
raise exceptions.Unauthorized(description)
|
||||||
elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
|
elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
|
||||||
raise exceptions.NetworkError('File too large for uploading. '
|
raise exceptions.NetworkError('File too large for uploading. '
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ TelegramAPIError
|
||||||
NotFound
|
NotFound
|
||||||
MethodNotKnown
|
MethodNotKnown
|
||||||
PhotoAsInputFileRequired
|
PhotoAsInputFileRequired
|
||||||
|
ToMuchMessages
|
||||||
ConflictError
|
ConflictError
|
||||||
TerminatedByOtherGetUpdates
|
TerminatedByOtherGetUpdates
|
||||||
CantGetUpdates
|
CantGetUpdates
|
||||||
|
|
@ -28,6 +29,7 @@ TelegramAPIError
|
||||||
BotKicked
|
BotKicked
|
||||||
BotBlocked
|
BotBlocked
|
||||||
UserDeactivated
|
UserDeactivated
|
||||||
|
CantInitiateConversation
|
||||||
NetworkError
|
NetworkError
|
||||||
RetryAfter
|
RetryAfter
|
||||||
MigrateToChat
|
MigrateToChat
|
||||||
|
|
@ -147,6 +149,13 @@ class PhotoAsInputFileRequired(BadRequest, _MatchErrorMixin):
|
||||||
match = 'Photo should be uploaded as an InputFile'
|
match = 'Photo should be uploaded as an InputFile'
|
||||||
|
|
||||||
|
|
||||||
|
class ToMuchMessages(BadRequest, _MatchErrorMixin):
|
||||||
|
"""
|
||||||
|
Will be raised when you try to send media group with more than 10 items.
|
||||||
|
"""
|
||||||
|
match = 'Too much messages to send as an album'
|
||||||
|
|
||||||
|
|
||||||
class BadWebhook(BadRequest):
|
class BadWebhook(BadRequest):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -203,6 +212,10 @@ class UserDeactivated(Unauthorized, _MatchErrorMixin):
|
||||||
match = 'user is deactivated'
|
match = 'user is deactivated'
|
||||||
|
|
||||||
|
|
||||||
|
class CantInitiateConversation(Unauthorized, _MatchErrorMixin):
|
||||||
|
match = 'bot can\'t initiate conversation with a user'
|
||||||
|
|
||||||
|
|
||||||
class NetworkError(TelegramAPIError):
|
class NetworkError(TelegramAPIError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue