add a handler for unknown HTTP errors

This change adds logic to handle a situation where an error response has
been received by HTTP but its body schema is an unknown format.

This issue came up during a review of related changes:
https://review.opendev.org/#/c/662281/
https://review.opendev.org/#/c/662281/7/keystoneauth1/exceptions/http.py

Change-Id: I21a33052e951f515988fdfd8ab1f42440ca9d4f8
This commit is contained in:
Michael McCune 2019-06-04 15:56:19 -04:00
parent 01d2da9e47
commit 96559d6009
3 changed files with 19 additions and 0 deletions

View File

@ -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

View File

@ -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):

View File

@ -0,0 +1,4 @@
---
fixes:
- Add logic to handle HTTP error responses that do not conform to a known
schema.