Return response as error if not valid json object

If the response returned by Mistral do not contain a valid json an
exception is thrown by the client due to invalid json format.
If there's a ValueError exception and it's an error code try to return
the response text instead. (Ex: Authorization Failed )

This may be a temporary fix if the BE is able to return the json
error msg returned by keystone.

Change-Id: I540f3aaa35fb15adc04bf0a33e46af8ac614c814
Closes-Bug: #1316298
This commit is contained in:
Leandro I. Costantino
2014-05-05 16:55:33 -03:00
parent 066ed82120
commit 762e1cdc3c

View File

@@ -133,8 +133,11 @@ class ResourceManager(object):
return self.resource_class.resource_name + 's'
def _raise_api_exception(self, resp):
error_data = get_json(resp)
raise APIException(error_data["faultstring"])
try:
error_data = get_json(resp).get("faultstring")
except ValueError:
error_data = resp.content
raise APIException(error_data)
def get_json(response):