diff --git a/keystoneauth1/exceptions/http.py b/keystoneauth1/exceptions/http.py index 768442e5..4a5d393b 100644 --- a/keystoneauth1/exceptions/http.py +++ b/keystoneauth1/exceptions/http.py @@ -436,6 +436,8 @@ def from_response(response, method, url): kwargs["message"] = "{}{}".format(msg_hdr, errors[0].get("title")) kwargs["details"] = errors[0].get("detail") + else: + kwargs["message"] = "Unrecognized schema in response body." elif content_type.startswith("text/"): kwargs["details"] = response.text diff --git a/keystoneauth1/tests/unit/test_session.py b/keystoneauth1/tests/unit/test_session.py index 0a39123e..d24728d8 100644 --- a/keystoneauth1/tests/unit/test_session.py +++ b/keystoneauth1/tests/unit/test_session.py @@ -641,6 +641,19 @@ class SessionTests(utils.TestCase): self.assertEqual(ex.message, msg) self.assertIsNone(ex.details) + def test_error_message_unknown_schema(self): + error_message = 'Uh oh, things went bad!' + payload = json.dumps(error_message) + self.stub_url('GET', status_code=9000, text=payload, + headers={'Content-Type': 'application/json'}) + session = client_session.Session() + + msg = 'Unrecognized schema in response body. (HTTP 9000)' + try: + session.get(self.TEST_URL) + except exceptions.HttpError as ex: + self.assertEqual(ex.message, msg) + class RedirectTests(utils.TestCase): diff --git a/releasenotes/notes/improve-http-error-handling.yaml b/releasenotes/notes/improve-http-error-handling.yaml new file mode 100644 index 00000000..99513f30 --- /dev/null +++ b/releasenotes/notes/improve-http-error-handling.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - Add logic to handle HTTP error responses that do not conform to a known + schema.