Skip to content

Commit 83c374f

Browse files
committed
Add conflicting bot id to conflict error message.
1 parent d4b5bd4 commit 83c374f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

telegram/error.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919
"""This module contains an object that represents Telegram errors."""
20+
import re
2021

2122

2223
def _lstrip_str(in_s, lstr):
@@ -57,7 +58,6 @@ class Unauthorized(TelegramError):
5758

5859

5960
class InvalidToken(TelegramError):
60-
6161
def __init__(self):
6262
super(InvalidToken, self).__init__('Invalid token')
6363

@@ -71,7 +71,6 @@ class BadRequest(NetworkError):
7171

7272

7373
class TimedOut(NetworkError):
74-
7574
def __init__(self):
7675
super(TimedOut, self).__init__('Timed out')
7776

@@ -100,3 +99,12 @@ def __init__(self, retry_after):
10099
super(RetryAfter,
101100
self).__init__('Flood control exceeded. Retry in {} seconds'.format(retry_after))
102101
self.retry_after = float(retry_after)
102+
103+
104+
class Conflict(TelegramError):
105+
def __init__(self, msg, url):
106+
match = re.search(r'bot(\d+):.*/', url)
107+
if match:
108+
msg += '. Conflicting bot id: {}'.format(match.group(1))
109+
110+
super(Conflict, self).__init__(msg)

telegram/utils/request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
from telegram import (InputFile, TelegramError)
4444
from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,
45-
RetryAfter, InvalidToken)
45+
RetryAfter, InvalidToken, Conflict)
4646

4747
logging.getLogger('urllib3').setLevel(logging.WARNING)
4848

@@ -215,6 +215,8 @@ def _request_wrapper(self, *args, **kwargs):
215215
raise BadRequest(message)
216216
elif resp.status == 404:
217217
raise InvalidToken()
218+
elif resp.status == 409:
219+
raise Conflict(message, args[1])
218220
elif resp.status == 413:
219221
raise NetworkError('File too large. Check telegram api limits '
220222
'https://core.telegram.org/bots/api#senddocument')

0 commit comments

Comments
 (0)