From 09fa911ffaa5a6c782e66112fe43fac248f7aa11 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Tue, 22 Aug 2017 20:28:22 +0300 Subject: [PATCH] Add ConflictError (309) --- aiogram/bot/api.py | 4 +++- aiogram/utils/exceptions.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index 14cd0dba..9cd8fdf4 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -7,7 +7,7 @@ import aiohttp from ..utils import json from ..utils.exceptions import ValidationError, TelegramAPIError, BadRequest, Unauthorized, NetworkError, RetryAfter, \ - MigrateToChat + MigrateToChat, ConflictError from ..utils.helper import Helper, HelperMode, Item # Main aiogram logger @@ -66,6 +66,8 @@ async def _check_result(method_name, response): raise MigrateToChat(result_json['migrate_to_chat_id']) elif response.status == HTTPStatus.BAD_REQUEST: raise BadRequest(description) + elif response.status == HTTPStatus.CONFLICT: + raise ConflictError(description) elif response.status in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN]: raise Unauthorized(description) elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE: diff --git a/aiogram/utils/exceptions.py b/aiogram/utils/exceptions.py index 4a14f914..0bf3a030 100644 --- a/aiogram/utils/exceptions.py +++ b/aiogram/utils/exceptions.py @@ -1,11 +1,11 @@ -_PREFIXES = ['Error: ', '[Error]: ', 'Bad Request: '] +_PREFIXES = ['Error: ', '[Error]: ', 'Bad Request: ', 'Conflict: '] def _clean_message(text): for prefix in _PREFIXES: if text.startswith(prefix): text = text[len(prefix):] - return text + return (text[0].upper() + text[1:]).strip() class TelegramAPIError(Exception): @@ -21,6 +21,10 @@ class BadRequest(TelegramAPIError): pass +class ConflictError(TelegramAPIError): + pass + + class Unauthorized(TelegramAPIError): pass