From 748cf2d97f7c1f00e1ffc0542a0625c5c2cdac1a Mon Sep 17 00:00:00 2001 From: dongwenjuan Date: Mon, 13 Jun 2016 16:57:43 +0800 Subject: [PATCH] add the response msg as input to the ClientException Change-Id: I96fba8fed1881de728cf49d7b2394d29617d6fc8 Signed-off-by: dongwenjuan --- vitrageclient/exc.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vitrageclient/exc.py b/vitrageclient/exc.py index 084e0fa..afad83a 100644 --- a/vitrageclient/exc.py +++ b/vitrageclient/exc.py @@ -9,6 +9,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import json class ClientException(Exception): @@ -33,4 +34,13 @@ class ClientException(Exception): def from_response(resp, url, method): - return ClientException(resp.status_code, url=url, method=method) + msg = None + if resp.text: + try: + body = json.loads(resp.text) + msg = body.get('description', None) + except Exception as e: + print ('get msg failed, resp.text:%s, e:%s ' % (resp.text, e)) + + return ClientException(resp.status_code, message=msg, + url=url, method=method)