Improve feedback message in SSL error

Adds the error message to give a hint to the user about
what happened.

Change-Id: I9ca56de8592e65194062038c81b468be72ffb2d9
Closes-Bug: 1297280
This commit is contained in:
Rodrigo Duarte Sousa
2014-10-20 22:46:33 -03:00
parent cfad7da20e
commit cccc065516
2 changed files with 21 additions and 2 deletions

View File

@@ -406,8 +406,9 @@ class Session(object):
try: try:
try: try:
resp = self.session.request(method, url, **kwargs) resp = self.session.request(method, url, **kwargs)
except requests.exceptions.SSLError: except requests.exceptions.SSLError as e:
msg = _('SSL exception connecting to %s') % url msg = _('SSL exception connecting to %(url)s: '
'%(error)s') % {'url': url, 'error': e}
raise exceptions.SSLError(msg) raise exceptions.SSLError(msg)
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
msg = _('Request to %s timed out') % url msg = _('Request to %s timed out') % url

View File

@@ -25,6 +25,7 @@ from testtools import matchers
from keystoneclient import adapter from keystoneclient import adapter
from keystoneclient.auth import base from keystoneclient.auth import base
from keystoneclient import exceptions from keystoneclient import exceptions
from keystoneclient.i18n import _
from keystoneclient import session as client_session from keystoneclient import session as client_session
from keystoneclient.tests.unit import utils from keystoneclient.tests.unit import utils
@@ -218,6 +219,23 @@ class SessionTests(utils.TestCase):
client_session.Session(session=mock_session) client_session.Session(session=mock_session)
self.assertFalse(mock_session.mount.called) self.assertFalse(mock_session.mount.called)
def test_ssl_error_message(self):
error = uuid.uuid4().hex
def _ssl_error(request, context):
raise requests.exceptions.SSLError(error)
self.stub_url('GET', text=_ssl_error)
session = client_session.Session()
# The exception should contain the URL and details about the SSL error
msg = _('SSL exception connecting to %(url)s: %(error)s') % {
'url': self.TEST_URL, 'error': error}
self.assertRaisesRegexp(exceptions.SSLError,
msg,
session.get,
self.TEST_URL)
class RedirectTests(utils.TestCase): class RedirectTests(utils.TestCase):