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
(cherry picked from commit a5e1e73e83)
This commit is contained in:
committed by
Renat Akhmerov
parent
bf56d02db7
commit
ce87eedb2c
@@ -135,7 +135,8 @@ class ResourceManager(object):
|
|||||||
|
|
||||||
def _raise_api_exception(self, resp):
|
def _raise_api_exception(self, resp):
|
||||||
try:
|
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:
|
except ValueError:
|
||||||
error_data = resp.content
|
error_data = resp.content
|
||||||
raise APIException(error_code=resp.status_code,
|
raise APIException(error_code=resp.status_code,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class FakeResponse(object):
|
|||||||
def __init__(self, status_code, content=None):
|
def __init__(self, status_code, content=None):
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
self.content = content
|
self.content = content
|
||||||
|
self.headers = {}
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
return json.loads(self.content)
|
return json.loads(self.content)
|
||||||
|
|||||||
Reference in New Issue
Block a user