From 762e1cdc3c50b677555ef99207cfdf3f609cdc3d Mon Sep 17 00:00:00 2001 From: "Leandro I. Costantino" Date: Mon, 5 May 2014 16:55:33 -0300 Subject: [PATCH] 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 --- mistralclient/api/base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mistralclient/api/base.py b/mistralclient/api/base.py index bfac5649..522927a9 100644 --- a/mistralclient/api/base.py +++ b/mistralclient/api/base.py @@ -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):