mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
pass errormessage to Unauthorized (#597)
This commit is contained in:
parent
ed49bdb19c
commit
f3aca42e69
3 changed files with 3 additions and 5 deletions
|
@ -62,9 +62,7 @@ class TelegramError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class Unauthorized(TelegramError):
|
class Unauthorized(TelegramError):
|
||||||
|
pass
|
||||||
def __init__(self):
|
|
||||||
super(Unauthorized, self).__init__('Unauthorized')
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidToken(TelegramError):
|
class InvalidToken(TelegramError):
|
||||||
|
|
|
@ -183,7 +183,7 @@ class Request(object):
|
||||||
raise NetworkError('Unknown HTTPError {0}'.format(resp.status))
|
raise NetworkError('Unknown HTTPError {0}'.format(resp.status))
|
||||||
|
|
||||||
if resp.status in (401, 403):
|
if resp.status in (401, 403):
|
||||||
raise Unauthorized()
|
raise Unauthorized(message)
|
||||||
elif resp.status == 400:
|
elif resp.status == 400:
|
||||||
raise BadRequest(message)
|
raise BadRequest(message)
|
||||||
elif resp.status == 404:
|
elif resp.status == 404:
|
||||||
|
|
|
@ -693,7 +693,7 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
||||||
def test_bootstrap_retries_unauth(self):
|
def test_bootstrap_retries_unauth(self):
|
||||||
retries = 3
|
retries = 3
|
||||||
self._setup_updater(
|
self._setup_updater(
|
||||||
'', messages=0, bootstrap_retries=retries, bootstrap_err=Unauthorized())
|
'', messages=0, bootstrap_retries=retries, bootstrap_err=Unauthorized("Unauthorized"))
|
||||||
|
|
||||||
self.assertRaises(Unauthorized, self.updater._bootstrap, retries, False, 'path', None)
|
self.assertRaises(Unauthorized, self.updater._bootstrap, retries, False, 'path', None)
|
||||||
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
self.assertEqual(self.updater.bot.bootstrap_attempts, 1)
|
||||||
|
|
Loading…
Reference in a new issue