pass errormessage to Unauthorized (#597)

This commit is contained in:
Eldinnie 2017-05-12 17:38:36 +02:00 committed by Jannes Höke
parent ed49bdb19c
commit f3aca42e69
3 changed files with 3 additions and 5 deletions

View file

@ -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):

View file

@ -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:

View file

@ -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)