Commit 31a351c6 authored by Joshua Roesslein's avatar Joshua Roesslein
Browse files

TweepError now includes the HTTPResponse object of the failed call.

Example:
	try:
		api.get_status(0)
	except TweepError, e:
		e.response // <-- HTTPResponse object
parent 7e9b4e3c
......@@ -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())
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment