From a5e1e73e837e7f356b3a5c4f1fcfaef0d31aa5b8 Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Thu, 8 Oct 2015 16:47:41 +0800 Subject: [PATCH] Show exact error message when authentication falied instead of HTML body When using pecan.abort() on server side, client side will see response bodies for HTTP errors, which is not readable for end users. This patch will let mistral client extract error message from header returned by mistral serivce, currently, it's only used for authentication failure. Closes-Bug: #1502840 Change-Id: I20a7f845676ffe23d93334d171332d717994d937 --- mistralclient/api/base.py | 3 ++- mistralclient/tests/unit/base.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mistralclient/api/base.py b/mistralclient/api/base.py index 44018e89..e25a0a2c 100644 --- a/mistralclient/api/base.py +++ b/mistralclient/api/base.py @@ -135,7 +135,8 @@ class ResourceManager(object): def _raise_api_exception(self, resp): try: - error_data = get_json(resp).get("faultstring") + error_data = (resp.headers.get("Server-Error-Message", None) or + get_json(resp).get("faultstring")) except ValueError: error_data = resp.content raise APIException(error_code=resp.status_code, diff --git a/mistralclient/tests/unit/base.py b/mistralclient/tests/unit/base.py index 0ac01ff1..5989becb 100644 --- a/mistralclient/tests/unit/base.py +++ b/mistralclient/tests/unit/base.py @@ -24,6 +24,7 @@ class FakeResponse(object): def __init__(self, status_code, content=None): self.status_code = status_code self.content = content + self.headers = {} def json(self): return json.loads(self.content)