Customized response sent in case of fault condition.

When duplicate workbook or workflow is created,
html respose is sent because content type
of result is 'plain/text'.

Code has been change to send 'application/json'
content type in case of exception is araise.

Change-Id: Icef1f8c5c615e21bb9da5a3d3bef9dacd308d242
Closes-Bug: #1501172
This commit is contained in:
hardik 2015-09-14 05:00:00 +05:30
parent 54a683356c
commit 493fcc5f0f
2 changed files with 10 additions and 4 deletions

View File

@ -180,7 +180,7 @@ class WorkflowsController(rest.RestController, hooks.HookController):
return Workflows(workflows=workflow_list).to_string()
@rest_utils.wrap_pecan_controller_exception
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(None, wtypes.text, status_code=204)
def delete(self, name):
"""Delete the named workflow."""
@ -195,7 +195,7 @@ class WorkflowsController(rest.RestController, hooks.HookController):
db_api.delete_workflow_definition(name)
@rest_utils.wrap_pecan_controller_exception
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(Workflows, types.uuid, int, types.uniquelist,
types.list, types.uniquelist)
def get_all(self, marker=None, limit=None, sort_keys='created_at',

View File

@ -15,9 +15,11 @@
# limitations under the License.
import functools
import json
import pecan
import six
from webob import Response
from wsme import exc
from mistral import exceptions as ex
@ -47,8 +49,12 @@ def wrap_pecan_controller_exception(func):
try:
return func(*args, **kwargs)
except ex.MistralException as excp:
pecan.response.translatable_error = excp
pecan.abort(excp.http_code, six.text_type(excp))
return Response(
status=excp.http_code,
content_type='application/json',
body=json.dumps(dict(
faultstring=six.text_type(excp))))
return wrapped