in libcloud/common/openstack.py [0:0]
def parse_error(self):
body = self.parse_body()
if self.has_content_type("application/xml"):
text = "; ".join([err.text or "" for err in body.getiterator() if err.text])
elif self.has_content_type("application/json"):
values = list(body.values())
context = self.connection.context
driver = self.connection.driver
key_pair_name = context.get("key_pair_name", None)
if (
len(values) > 0
and "code" in values[0]
and values[0]["code"] == 404
and key_pair_name
):
raise KeyPairDoesNotExistError(name=key_pair_name, driver=driver)
elif len(values) > 0 and "message" in values[0]:
text = ";".join([fault_data["message"] for fault_data in values])
else:
text = body
else:
# while we hope a response is always one of xml or json, we have
# seen html or text in the past, its not clear we can really do
# something to make it more readable here, so we will just pass
# it along as the whole response body in the text variable.
text = body
return "{} {} {}".format(self.status, self.error, text)