Moooore error types.

This commit is contained in:
Alex Root Junior 2018-07-15 21:49:53 +03:00
parent 59bde14db3
commit ebc0a94201

View file

@ -9,8 +9,13 @@ TelegramAPIError
MessageToDeleteNotFound
MessageIdentifierNotSpecified
MessageTextIsEmpty
MessageCantBeEdited
MessageToEditNotFound
ToMuchMessages
ObjectExpectedAsReplyMarkup
InlineKeyboardExpected
ChatNotFound
ChatDescriptionIsNotModified
InvalidQueryID
InvalidPeerID
InvalidHTTPUrlContent
@ -29,11 +34,19 @@ TelegramAPIError
MethodNotKnown
PhotoAsInputFileRequired
InvalidStickersSet
NoStickerInRequest
ChatAdminRequired
NotEnoughRightsToPinMessage
CantDemoteChatCreator
CantRestrictSelf
PhotoDimensions
UnavailableMembers
TypeOfFileMismatch
WrongRemoteFileIdSpecified
PaymentProviderInvalid
CurrencyTotalAmountInvalid
CantParseUrl
CantParseEntities
ConflictError
TerminatedByOtherGetUpdates
CantGetUpdates
@ -42,6 +55,7 @@ TelegramAPIError
BotBlocked
UserDeactivated
CantInitiateConversation
CantTalkWithBots
NetworkError
RetryAfter
MigrateToChat
@ -91,15 +105,6 @@ class _MatchErrorMixin:
"""
return cls.match.lower() in message
@classmethod
def throw(cls):
"""
Throw error
:raise: this
"""
raise cls(cls.text or cls.match)
@classmethod
def detect(cls, description):
description = description.lower()
@ -107,7 +112,7 @@ class _MatchErrorMixin:
if err is cls:
continue
if err.check(description):
err.throw()
raise err(cls.text or description)
raise cls(description)
@ -164,6 +169,14 @@ class MessageTextIsEmpty(MessageError):
match = 'Message text is empty'
class MessageCantBeEdited(MessageError):
match = 'message can\'t be edited'
class MessageToEditNotFound(MessageError):
match = 'message to edit not found'
class ToMuchMessages(MessageError):
"""
Will be raised when you try to send media group with more than 10 items.
@ -171,10 +184,22 @@ class ToMuchMessages(MessageError):
match = 'Too much messages to send as an album'
class ObjectExpectedAsReplyMarkup(BadRequest):
match = 'object expected as reply markup'
class InlineKeyboardExpected(BadRequest):
match = 'inline keyboard expected'
class ChatNotFound(BadRequest):
match = 'chat not found'
class ChatDescriptionIsNotModified(BadRequest):
match = 'chat description is not modified'
class InvalidQueryID(BadRequest):
match = 'QUERY_ID_INVALID'
text = 'Invalid query ID'
@ -228,11 +253,23 @@ class InvalidStickersSet(BadRequest):
text = 'Stickers set is invalid'
class NoStickerInRequest(BadRequest):
match = 'there is no sticker in the request'
class ChatAdminRequired(BadRequest):
match = 'CHAT_ADMIN_REQUIRED'
text = 'Admin permissions is required!'
class NotEnoughRightsToPinMessage(BadRequest):
match = 'not enough rights to pin a message'
class CantDemoteChatCreator(BadRequest):
match = 'can\'t demote chat creator'
class CantRestrictSelf(BadRequest):
match = "can't restrict self"
text = "Admin can't restrict self."
@ -251,6 +288,20 @@ class TypeOfFileMismatch(BadRequest):
match = 'type of file mismatch'
class WrongRemoteFileIdSpecified(BadRequest):
match = 'wrong remote file id specified'
class PaymentProviderInvalid(BadRequest):
match = 'PAYMENT_PROVIDER_INVALID'
text = 'payment provider invalid'
class CurrencyTotalAmountInvalid(BadRequest):
match = 'currency_total_amount_invalid'
text = 'currency total amount invalid'
class BadWebhook(BadRequest):
__group = True
@ -274,6 +325,10 @@ class CantParseUrl(BadRequest):
match = 'can\'t parse URL'
class CantParseEntities(BadRequest):
match = 'can\'t parse entities'
class NotFound(TelegramAPIError, _MatchErrorMixin):
__group = True
@ -316,6 +371,10 @@ class CantInitiateConversation(Unauthorized):
match = 'bot can\'t initiate conversation with a user'
class CantTalkWithBots(Unauthorized):
match = 'bot can\'t send messages to bots'
class NetworkError(TelegramAPIError):
pass