New exception: RetryAfter

Also, small fix to the description text of ChatMigrated
This commit is contained in:
Noam Meltzer 2016-10-04 01:27:45 +03:00
parent 7cf5009517
commit 2463b4b9c8
2 changed files with 20 additions and 4 deletions

View file

@ -94,8 +94,20 @@ class ChatMigrated(TelegramError):
Args:
new_chat_id (int):
Returns:
"""
super(ChatMigrated,
self).__init__('Group migrated to supergroup. New chat id: {}'.format(new_chat_id))
self.new_chat_id = new_chat_id
class RetryAfter(TelegramError):
def __init__(self, retry_after):
"""
Args:
retry_after (int):
"""
super(ChatMigrated, self).__init__('Chat migrated')
self.new_chat_id = new_chat_id
super(RetryAfter,
self).__init__('Flood control exceeded. Retry in {} seconds'.format(retry_after))
self.retry_after = retry_after

View file

@ -31,7 +31,8 @@ import urllib3
from urllib3.connection import HTTPConnection
from telegram import (InputFile, TelegramError)
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated, \
RetryAfter
logging.getLogger('urllib3').setLevel(logging.WARNING)
@ -105,6 +106,9 @@ class Request(object):
migrate_to_chat_id = parameters.get('migrate_to_chat_id')
if migrate_to_chat_id:
raise ChatMigrated(migrate_to_chat_id)
retry_after = parameters.get('retry_after')
if retry_after:
raise RetryAfter(retry_after)
if description:
return description