mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-17 04:39:55 +01:00
Add Conflict error (HTTP error code 409) (#1154)
* Add conflicting bot id to conflict error message. * Add test and comment to conflict error * Don't extract bot id in Conflict exception per PR comments
This commit is contained in:
parent
9d99660ba9
commit
c9630ee8c5
3 changed files with 21 additions and 4 deletions
|
@ -57,7 +57,6 @@ class Unauthorized(TelegramError):
|
|||
|
||||
|
||||
class InvalidToken(TelegramError):
|
||||
|
||||
def __init__(self):
|
||||
super(InvalidToken, self).__init__('Invalid token')
|
||||
|
||||
|
@ -71,7 +70,6 @@ class BadRequest(NetworkError):
|
|||
|
||||
|
||||
class TimedOut(NetworkError):
|
||||
|
||||
def __init__(self):
|
||||
super(TimedOut, self).__init__('Timed out')
|
||||
|
||||
|
@ -100,3 +98,16 @@ class RetryAfter(TelegramError):
|
|||
super(RetryAfter,
|
||||
self).__init__('Flood control exceeded. Retry in {} seconds'.format(retry_after))
|
||||
self.retry_after = float(retry_after)
|
||||
|
||||
|
||||
class Conflict(TelegramError):
|
||||
"""
|
||||
Raised when a long poll or webhook conflicts with another one.
|
||||
|
||||
Args:
|
||||
msg (:obj:`str`): The message from telegrams server.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, msg):
|
||||
super(Conflict, self).__init__(msg)
|
||||
|
|
|
@ -44,7 +44,7 @@ except ImportError: # pragma: no cover
|
|||
|
||||
from telegram import (InputFile, TelegramError, InputMedia)
|
||||
from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,
|
||||
RetryAfter, InvalidToken)
|
||||
RetryAfter, InvalidToken, Conflict)
|
||||
|
||||
|
||||
def _render_part(self, name, value):
|
||||
|
@ -238,6 +238,8 @@ class Request(object):
|
|||
raise BadRequest(message)
|
||||
elif resp.status == 404:
|
||||
raise InvalidToken()
|
||||
elif resp.status == 409:
|
||||
raise Conflict(message)
|
||||
elif resp.status == 413:
|
||||
raise NetworkError('File too large. Check telegram api limits '
|
||||
'https://core.telegram.org/bots/api#senddocument')
|
||||
|
|
|
@ -20,7 +20,7 @@ import pytest
|
|||
|
||||
from telegram import TelegramError
|
||||
from telegram.error import Unauthorized, InvalidToken, NetworkError, BadRequest, TimedOut, \
|
||||
ChatMigrated, RetryAfter
|
||||
ChatMigrated, RetryAfter, Conflict
|
||||
|
||||
|
||||
class TestErrors(object):
|
||||
|
@ -83,3 +83,7 @@ class TestErrors(object):
|
|||
def test_retry_after(self):
|
||||
with pytest.raises(RetryAfter, match="Flood control exceeded. Retry in 12 seconds"):
|
||||
raise RetryAfter(12)
|
||||
|
||||
def test_conflict(self):
|
||||
with pytest.raises(Conflict, match='Something something.'):
|
||||
raise Conflict('Something something.')
|
||||
|
|
Loading…
Add table
Reference in a new issue