From 411202de45d7bc03c7e73604f097b22b76e9371b Mon Sep 17 00:00:00 2001 From: Alex RootJunior Date: Sat, 13 Apr 2019 04:41:35 +0300 Subject: [PATCH] More poll errors --- aiogram/utils/exceptions.py | 85 ++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/aiogram/utils/exceptions.py b/aiogram/utils/exceptions.py index b08c681d..50f8de4c 100644 --- a/aiogram/utils/exceptions.py +++ b/aiogram/utils/exceptions.py @@ -7,16 +7,25 @@ TelegramAPIError MessageNotModified MessageToForwardNotFound MessageToDeleteNotFound - MessageWithPollNotFound - MessageIsNotAPoll MessageIdentifierNotSpecified MessageTextIsEmpty MessageCantBeEdited MessageCantBeDeleted MessageToEditNotFound ToMuchMessages - PollCantBeStopped - PollHasAlreadyClosed + PollError + PollCantBeStopped + PollHasAlreadyClosed + PollsCantBeSentToPrivateChats + PollSizeError + PollMustHaveMoreOptions + PollCantHaveMoreOptions + PollsOptionsLengthTooLong + PollOptionsMustBeNonEmpty + PollQuestionMustBeNonEmpty + + MessageWithPollNotFound (with MessageError) + MessageIsNotAPoll (with MessageError) ObjectExpectedAsReplyMarkup InlineKeyboardExpected ChatNotFound @@ -168,20 +177,6 @@ class MessageToDeleteNotFound(MessageError): match = 'message to delete not found' -class MessageWithPollNotFound(MessageError): - """ - Will be raised when you try to stop poll with message without poll - """ - match = 'message with poll to stop not found' - - -class MessageIsNotAPoll(MessageError): - """ - Will be raised when you try to stop poll with message without poll - """ - match = 'message is not a poll' - - class MessageIdentifierNotSpecified(MessageError): match = 'message identifier is not specified' @@ -221,14 +216,64 @@ class InlineKeyboardExpected(BadRequest): match = 'inline keyboard expected' -class PollCantBeStopped(BadRequest): +class PollError(BadRequest): + __group = True + + +class PollCantBeStopped(PollError): match = "poll can't be stopped" -class PollHasAlreadyBeenClosed(BadRequest): +class PollHasAlreadyBeenClosed(PollError): match = 'poll has already been closed' +class PollsCantBeSentToPrivateChats(PollError): + match = "polls can't be sent to private chats" + + +class PollSizeError(PollError): + __group = True + + +class PollMustHaveMoreOptions(PollSizeError): + match = "poll must have at least 2 option" + + +class PollCantHaveMoreOptions(PollSizeError): + match = "poll can't have more than 10 options" + + +class PollOptionsMustBeNonEmpty(PollSizeError): + match = "poll options must be non-empty" + + +class PollQuestionMustBeNonEmpty(PollSizeError): + match = "poll question must be non-empty" + + +class PollOptionsLengthTooLong(PollSizeError): + match = "poll options length must not exceed 100" + + +class PollQuestionLengthTooLong(PollSizeError): + match = "poll question length must not exceed 255" + + +class MessageWithPollNotFound(PollError, MessageError): + """ + Will be raised when you try to stop poll with message without poll + """ + match = 'message with poll to stop not found' + + +class MessageIsNotAPoll(PollError, MessageError): + """ + Will be raised when you try to stop poll with message without poll + """ + match = 'message is not a poll' + + class ChatNotFound(BadRequest): match = 'chat not found'