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:
parent
01d2da9e47
commit
96559d6009
@ -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
|
||||
|
@ -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):
|
||||
|
||||
|
4
releasenotes/notes/improve-http-error-handling.yaml
Normal file
4
releasenotes/notes/improve-http-error-handling.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Add logic to handle HTTP error responses that do not conform to a known
|
||||
schema.
|
Loading…
Reference in New Issue
Block a user