Return 400 for invalid Json for api v2
For invalid json, a ValueError is returned by python's json decoder. On v2, we now catch this and return a 400 (invalid_json) Change-Id: Idb76f051c6d09d5fd26f0a44fa75a0ffd9f37b6a Closes-Bug: #1288456
This commit is contained in:
parent
57d24f3858
commit
877055aca7
@ -14,6 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import pecan.core
|
||||
from designate import exceptions
|
||||
from designate.openstack.common import jsonutils
|
||||
|
||||
JSON_TYPES = ('application/json', 'application/json-patch+json')
|
||||
@ -30,7 +31,10 @@ class Request(pecan.core.Request):
|
||||
is not hardcoded to call pecans "request.json()" method.
|
||||
"""
|
||||
if self.content_type in JSON_TYPES:
|
||||
return jsonutils.load(self.body_file)
|
||||
try:
|
||||
return jsonutils.load(self.body_file)
|
||||
except ValueError as valueError:
|
||||
raise exceptions.InvalidJson(valueError.message)
|
||||
else:
|
||||
raise Exception('TODO: Unsupported Content Type')
|
||||
|
||||
|
@ -115,6 +115,10 @@ class InvalidSortKey(BadRequest):
|
||||
error_type = 'invalid_sort_key'
|
||||
|
||||
|
||||
class InvalidJson(BadRequest):
|
||||
error_type = 'invalid_json'
|
||||
|
||||
|
||||
class InvalidOperation(BadRequest):
|
||||
error_code = 400
|
||||
error_type = 'invalid_operation'
|
||||
|
Loading…
Reference in New Issue
Block a user