mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Small changes in exceptions.
This commit is contained in:
parent
afe8b24c42
commit
b7bf22bb77
2 changed files with 5 additions and 4 deletions
|
|
@ -143,7 +143,7 @@ async def request(session, token, method, data=None, files=None, continue_retry=
|
||||||
async with session.post(url, data=data, **kwargs) as response:
|
async with session.post(url, data=data, **kwargs) as response:
|
||||||
return await _check_result(method, response)
|
return await _check_result(method, response)
|
||||||
except aiohttp.ClientError as e:
|
except aiohttp.ClientError as e:
|
||||||
raise TelegramAPIError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
|
raise NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
|
||||||
except RetryAfter as e:
|
except RetryAfter as e:
|
||||||
if continue_retry:
|
if continue_retry:
|
||||||
await asyncio.sleep(e.timeout)
|
await asyncio.sleep(e.timeout)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ def _clean_message(text):
|
||||||
return text. \
|
return text. \
|
||||||
lstrip('Error: '). \
|
lstrip('Error: '). \
|
||||||
lstrip('[Error]: '). \
|
lstrip('[Error]: '). \
|
||||||
lstrip('Bad Request: ')
|
lstrip('Bad Request: '). \
|
||||||
|
capitalize()
|
||||||
|
|
||||||
|
|
||||||
class TelegramAPIError(Exception):
|
class TelegramAPIError(Exception):
|
||||||
|
|
@ -28,11 +29,11 @@ class NetworkError(TelegramAPIError):
|
||||||
|
|
||||||
class RetryAfter(TelegramAPIError):
|
class RetryAfter(TelegramAPIError):
|
||||||
def __init__(self, retry_after):
|
def __init__(self, retry_after):
|
||||||
super(RetryAfter, self).__init__(f"Flood control exceeded. Retry in {retry_after} seconds")
|
super(RetryAfter, self).__init__(f"Flood control exceeded. Retry in {retry_after} seconds.")
|
||||||
self.timeout = retry_after
|
self.timeout = retry_after
|
||||||
|
|
||||||
|
|
||||||
class MigrateToChat(TelegramAPIError):
|
class MigrateToChat(TelegramAPIError):
|
||||||
def __init__(self, chat_id):
|
def __init__(self, chat_id):
|
||||||
super(MigrateToChat, self).__init__(f"The group has been migrated to a supergroup. New id: {chat_id}")
|
super(MigrateToChat, self).__init__(f"The group has been migrated to a supergroup. New id: {chat_id}.")
|
||||||
self.migrate_to_chat_id = chat_id
|
self.migrate_to_chat_id = chat_id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue