diff --git a/common.py b/common.py index b4185cb..5320a81 100644 --- a/common.py +++ b/common.py @@ -79,7 +79,11 @@ def _requests_fn(fn, url, parse_json=False, **kwargs): """Wraps requests.* and adds raise_for_status() and User-Agent.""" kwargs.setdefault('headers', {}).update(HEADERS) - resp = fn(url, **kwargs) + try: + resp = fn(url, **kwargs) + except (requests.ConnectionError, requests.Timeout) as e: + logging.warning(url, exc_info=True) + raise exc.HTTPBadGateway(unicode(e)) logging.info('Got %s headers:%s', resp.status_code, resp.headers) type = content_type(resp) diff --git a/tests/test_common.py b/tests/test_common.py index ec6b2da..2839e73 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -58,3 +58,9 @@ class CommonTest(testutil.TestCase): def test_get_as2_not_acceptable(self, mock_get): with self.assertRaises(exc.HTTPBadGateway): resp = common.get_as2('http://orig') + + @mock.patch('requests.get', side_effect=requests.exceptions.SSLError) + def test_get_ssl_error(self, mock_get): + with self.assertRaises(exc.HTTPBadGateway): + resp = common.get_as2('http://orig') +