Use built-in Exception attributes for storing and retrieving error message.
Keeping msg as a property so it's backwards compatible. Note that this only fixes Python 2.x
This commit is contained in:
parent
8dfb076f11
commit
9c9aba3ec8
1 changed files with 9 additions and 8 deletions
|
|
@ -42,17 +42,18 @@ class TwythonError(Exception):
|
||||||
from twython import TwythonError, TwythonAPILimit, TwythonAuthError
|
from twython import TwythonError, TwythonAPILimit, TwythonAuthError
|
||||||
"""
|
"""
|
||||||
def __init__(self, msg, error_code=None, retry_after=None):
|
def __init__(self, msg, error_code=None, retry_after=None):
|
||||||
self.msg = msg
|
|
||||||
self.error_code = error_code
|
self.error_code = error_code
|
||||||
|
|
||||||
if error_code is not None and error_code in twitter_http_status_codes:
|
if error_code is not None and error_code in twitter_http_status_codes:
|
||||||
self.msg = '%s: %s -- %s' % \
|
msg = '%s: %s -- %s' % (twitter_http_status_codes[error_code][0],
|
||||||
(twitter_http_status_codes[error_code][0],
|
twitter_http_status_codes[error_code][1],
|
||||||
twitter_http_status_codes[error_code][1],
|
msg)
|
||||||
self.msg)
|
|
||||||
|
|
||||||
def __str__(self):
|
super(TwythonError, self).__init__(msg)
|
||||||
return repr(self.msg)
|
|
||||||
|
@property
|
||||||
|
def msg(self):
|
||||||
|
return self.args[0]
|
||||||
|
|
||||||
|
|
||||||
class TwythonAuthError(TwythonError):
|
class TwythonAuthError(TwythonError):
|
||||||
|
|
@ -69,7 +70,7 @@ class TwythonRateLimitError(TwythonError):
|
||||||
def __init__(self, msg, error_code, retry_after=None):
|
def __init__(self, msg, error_code, retry_after=None):
|
||||||
TwythonError.__init__(self, msg, error_code=error_code)
|
TwythonError.__init__(self, msg, error_code=error_code)
|
||||||
if isinstance(retry_after, int):
|
if isinstance(retry_after, int):
|
||||||
self.msg = '%s (Retry after %d seconds)' % (msg, retry_after)
|
self.args[0] = '%s (Retry after %d seconds)' % (self.args[0], retry_after)
|
||||||
|
|
||||||
|
|
||||||
class Twython(object):
|
class Twython(object):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue