mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Add ConflictError (309)
This commit is contained in:
parent
d4f1b72d92
commit
09fa911ffa
2 changed files with 9 additions and 3 deletions
|
|
@ -7,7 +7,7 @@ import aiohttp
|
||||||
|
|
||||||
from ..utils import json
|
from ..utils import json
|
||||||
from ..utils.exceptions import ValidationError, TelegramAPIError, BadRequest, Unauthorized, NetworkError, RetryAfter, \
|
from ..utils.exceptions import ValidationError, TelegramAPIError, BadRequest, Unauthorized, NetworkError, RetryAfter, \
|
||||||
MigrateToChat
|
MigrateToChat, ConflictError
|
||||||
from ..utils.helper import Helper, HelperMode, Item
|
from ..utils.helper import Helper, HelperMode, Item
|
||||||
|
|
||||||
# Main aiogram logger
|
# Main aiogram logger
|
||||||
|
|
@ -66,6 +66,8 @@ async def _check_result(method_name, response):
|
||||||
raise MigrateToChat(result_json['migrate_to_chat_id'])
|
raise MigrateToChat(result_json['migrate_to_chat_id'])
|
||||||
elif response.status == HTTPStatus.BAD_REQUEST:
|
elif response.status == HTTPStatus.BAD_REQUEST:
|
||||||
raise BadRequest(description)
|
raise BadRequest(description)
|
||||||
|
elif response.status == HTTPStatus.CONFLICT:
|
||||||
|
raise ConflictError(description)
|
||||||
elif response.status in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN]:
|
elif response.status in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN]:
|
||||||
raise Unauthorized(description)
|
raise Unauthorized(description)
|
||||||
elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
|
elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
_PREFIXES = ['Error: ', '[Error]: ', 'Bad Request: ']
|
_PREFIXES = ['Error: ', '[Error]: ', 'Bad Request: ', 'Conflict: ']
|
||||||
|
|
||||||
|
|
||||||
def _clean_message(text):
|
def _clean_message(text):
|
||||||
for prefix in _PREFIXES:
|
for prefix in _PREFIXES:
|
||||||
if text.startswith(prefix):
|
if text.startswith(prefix):
|
||||||
text = text[len(prefix):]
|
text = text[len(prefix):]
|
||||||
return text
|
return (text[0].upper() + text[1:]).strip()
|
||||||
|
|
||||||
|
|
||||||
class TelegramAPIError(Exception):
|
class TelegramAPIError(Exception):
|
||||||
|
|
@ -21,6 +21,10 @@ class BadRequest(TelegramAPIError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ConflictError(TelegramAPIError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Unauthorized(TelegramAPIError):
|
class Unauthorized(TelegramAPIError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue