From: Joshua Roesslein Date: Fri, 26 Feb 2010 06:25:18 +0000 (-0600) Subject: TweepError now includes the HTTPResponse object of the failed call. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=31a351c665ad8675a10b52351feecf8c9d24ba53;p=tweepy.git TweepError now includes the HTTPResponse object of the failed call. Example: try: api.get_status(0) except TweepError, e: e.response // <-- HTTPResponse object --- diff --git a/tweepy/binder.py b/tweepy/binder.py index bd508a5..437e2c3 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -139,7 +139,7 @@ def bind_api(**config): conn.request(self.method, url, headers=self.headers, body=self.post_data) resp = conn.getresponse() except Exception, e: - raise TweepError('Failed to send request: %s' % e) + raise TweepError('Failed to send request: %s' % e, resp) # Exit request loop if non-retry error code if self.retry_errors: @@ -158,7 +158,7 @@ def bind_api(**config): error_msg = self.api.parser.parse_error(self, resp.read()) except Exception: error_msg = "Twitter error response: status code = %s" % resp.status - raise TweepError(error_msg) + raise TweepError(error_msg, resp) # Parse the response payload result = self.api.parser.parse(self, resp.read()) diff --git a/tweepy/error.py b/tweepy/error.py index be6d227..f66f5d2 100644 --- a/tweepy/error.py +++ b/tweepy/error.py @@ -5,8 +5,9 @@ class TweepError(Exception): """Tweepy exception""" - def __init__(self, reason): + def __init__(self, reason, response=None): self.reason = str(reason) + self.response = response def __str__(self): return self.reason