Skip to content
Myr

Merge pull request #1891 from sigmavirus24/add-requests-to-exceptions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add request to RequestException

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 94badad, 07e0a61 · Browse files · 2 files+16 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−9 removed

  • other:+16 added−9 removed

2 files+16 added−9 removed

modified:requests/adapters.py+4 added-4 removed
370 unmodified lines
371 # All is well, return the connection to the pool.372 conn._put_conn(low_conn)373374 except socket.error as sockerr:375 raise ConnectionError(sockerr)375 raise ConnectionError(sockerr, request=request)376377 except MaxRetryError as e:378 raise ConnectionError(e)378 raise ConnectionError(e, request=request)379380 except _ProxyError as e:381 raise ProxyError(e)382383 except (_SSLError, _HTTPError) as e:384 if isinstance(e, _SSLError):385 raise SSLError(e)385 raise SSLError(e, request=request)386 elif isinstance(e, TimeoutError):387 raise Timeout(e)387 raise Timeout(e, request=request)388 else:389 raise390391 r = self.build_response(request, resp)
5 unmodified lines
modified:requests/exceptions.py+12 added-5 removed
12 unmodified lines
13class RequestException(IOError):14 """There was an ambiguous exception that occurred while handling your15 request."""1617 def __init__(self, *args, **kwargs):18 """19 Initialize RequestException with `request` and `response` objects.20 """21 response = kwargs.pop('response', None)22 self.response = response23 self.request = kwargs.pop('request', None)24 if (response is not None and not self.request and25 hasattr(response, 'request')):26 self.request = self.response.request27 super(RequestException, self).__init__(*args, **kwargs)282930class HTTPError(RequestException):31 """An HTTP error occurred."""3221 def __init__(self, *args, **kwargs):22 """ Initializes HTTPError with optional `response` object. """23 self.response = kwargs.pop('response', None)24 super(HTTPError, self).__init__(*args, **kwargs)332634class ConnectionError(RequestException):35 """A Connection error occurred."""3637
38 unmodified lines