From 31a351c665ad8675a10b52351feecf8c9d24ba53 Mon Sep 17 00:00:00 2001 From: Joshua Roesslein Date: Fri, 26 Feb 2010 00:25:18 -0600 Subject: [PATCH] TweepError now includes the HTTPResponse object of the failed call. Example: try: api.get_status(0) except TweepError, e: e.response // <-- HTTPResponse object --- tweepy/binder.py | 4 ++-- tweepy/error.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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 -- 2.25.1