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
This commit is contained in:
Lingxian Kong 2015-10-08 16:47:41 +08:00
parent e9b8e75b72
commit a5e1e73e83
2 changed files with 3 additions and 1 deletions

View File

@ -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,

View File

@ -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)