TweepError now includes the HTTPResponse object of the failed call.
authorJoshua Roesslein <jroesslein@gmail.com>
Fri, 26 Feb 2010 06:25:18 +0000 (00:25 -0600)
committerJoshua Roesslein <jroesslein@gmail.com>
Fri, 26 Feb 2010 06:25:18 +0000 (00:25 -0600)
Example:
try:
api.get_status(0)
except TweepError, e:
e.response // <-- HTTPResponse object

tweepy/binder.py
tweepy/error.py

index bd508a57a00c1290cd9360b4936e3fdcbe3b6ff6..437e2c3ba72819ff38006f89e2b5fea52dcf5094 100644 (file)
@@ -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())
index be6d227473aa81488b7f2092812098e3b58d1d0a..f66f5d2aebb4a3cf254e4e4a556ec592b66fb8e5 100644 (file)
@@ -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