From 0a1e527aec37b7c419a9bb976e3fcf3514570448 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 9 Mar 2012 08:51:03 -0800 Subject: [PATCH] Merge of maxcountryman --- AUTHORS.rst | 1 + requests/exceptions.py | 1 + requests/models.py | 13 ++++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 0e6e7ef6..9cfa7db0 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -87,3 +87,4 @@ Patches and Suggestions - Brendan Maguire - Chris Dary - Danver Braganza +- Max Countryman diff --git a/requests/exceptions.py b/requests/exceptions.py index 94860a88..d5b2ab17 100644 --- a/requests/exceptions.py +++ b/requests/exceptions.py @@ -14,6 +14,7 @@ class RequestException(RuntimeError): class HTTPError(RequestException): """An HTTP error occurred.""" + response = None class ConnectionError(RequestException): """A Connection error occurred.""" diff --git a/requests/models.py b/requests/models.py index a354eb2e..753e83ab 100644 --- a/requests/models.py +++ b/requests/models.py @@ -800,10 +800,17 @@ class Response(object): raise self.error if (self.status_code >= 300) and (self.status_code < 400) and not allow_redirects: - raise HTTPError('%s Redirection' % self.status_code) + http_error = HTTPError('%s Redirection' % self.status_code) + http_error.response = self + raise http_error elif (self.status_code >= 400) and (self.status_code < 500): - raise HTTPError('%s Client Error' % self.status_code) + http_error = HTTPError('%s Client Error' % self.status_code) + http_error.response = self + raise http_error + elif (self.status_code >= 500) and (self.status_code < 600): - raise HTTPError('%s Server Error' % self.status_code) + http_error = HTTPError('%s Server Error' % self.status_code) + http_error.response = self + raise http_error