mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 01:54:53 +00:00
Reorder exceptions in error detector.
This commit is contained in:
parent
5812243d5d
commit
afe8b24c42
1 changed files with 10 additions and 12 deletions
|
|
@ -49,33 +49,31 @@ async def _check_result(method_name, response):
|
||||||
:return: The result parsed to a JSON dictionary.
|
:return: The result parsed to a JSON dictionary.
|
||||||
"""
|
"""
|
||||||
body = await response.text()
|
body = await response.text()
|
||||||
log.debug(f"Response for {method_name}: {body}")
|
log.debug(f"Response for {method_name}: [{response.status}] {body}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result_json = await response.json(loads=json.loads)
|
result_json = await response.json(loads=json.loads)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
result_json = {}
|
result_json = {}
|
||||||
|
|
||||||
message = result_json.get('description') or body
|
description = result_json.get('description') or body
|
||||||
|
|
||||||
if response.status >= HTTPStatus.INTERNAL_SERVER_ERROR:
|
if HTTPStatus.OK <= response.status <= HTTPStatus.IM_USED:
|
||||||
raise TelegramAPIError(message)
|
return result_json.get('result')
|
||||||
|
elif 'retry_after' in result_json:
|
||||||
if 'retry_after' in result_json:
|
|
||||||
raise RetryAfter(result_json['retry_after'])
|
raise RetryAfter(result_json['retry_after'])
|
||||||
elif 'migrate_to_chat_id' in result_json:
|
elif 'migrate_to_chat_id' in result_json:
|
||||||
raise MigrateToChat(result_json['migrate_to_chat_id'])
|
raise MigrateToChat(result_json['migrate_to_chat_id'])
|
||||||
elif HTTPStatus.OK <= response.status <= HTTPStatus.IM_USED:
|
|
||||||
return result_json.get('result')
|
|
||||||
elif response.status == HTTPStatus.BAD_REQUEST:
|
elif response.status == HTTPStatus.BAD_REQUEST:
|
||||||
raise BadRequest(message)
|
raise BadRequest(description)
|
||||||
elif response.status in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN]:
|
elif response.status in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN]:
|
||||||
raise Unauthorized(message)
|
raise Unauthorized(description)
|
||||||
elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
|
elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
|
||||||
raise NetworkError('File too large for uploading. '
|
raise NetworkError('File too large for uploading. '
|
||||||
'Check telegram api limits https://core.telegram.org/bots/api#senddocument')
|
'Check telegram api limits https://core.telegram.org/bots/api#senddocument')
|
||||||
else:
|
elif response.status >= HTTPStatus.INTERNAL_SERVER_ERROR:
|
||||||
raise TelegramAPIError(f"{message} [{response.status}]")
|
raise TelegramAPIError(description)
|
||||||
|
raise TelegramAPIError(f"{description} [{response.status}]")
|
||||||
|
|
||||||
|
|
||||||
def _guess_filename(obj):
|
def _guess_filename(obj):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue