Fix response code for invalid requests

If in body of POST, PUT or PATCH requests there is
invalid json Sahara API reply with
500 "Internal Server Error" insted of
400 "Bad Request". In this commit I fix error code
and add error message to response.

Change-Id: I7ccf27e60c72e47e085690017e7eb19213930fdd
Closes-bug: #1632705
This commit is contained in:
Mikhail Lelyakin 2016-10-12 16:25:44 +03:00
parent b0f06e740e
commit c4e0315fbd

View File

@ -91,10 +91,10 @@ class Rest(flask.Blueprint):
auth_plugin=auth_plugin,
request_id=req_id)
context.set_ctx(ctx)
if flask.request.method in ['POST', 'PUT', 'PATCH']:
kwargs['data'] = request_data()
try:
if flask.request.method in ['POST', 'PUT', 'PATCH']:
kwargs['data'] = request_data()
return func(**kwargs)
except ex.Forbidden as e:
return access_denied(e)
@ -145,10 +145,10 @@ class RestV2(Rest):
auth_plugin=auth_plugin,
request_id=req_id)
context.set_ctx(ctx)
if flask.request.method in ['POST', 'PUT', 'PATCH']:
kwargs['data'] = request_data()
try:
if flask.request.method in ['POST', 'PUT', 'PATCH']:
kwargs['data'] = request_data()
return func(**kwargs)
except ex.Forbidden as e:
return access_denied(e)