diff options
author | Vinod Mangalpally <vinod.mang@rackspace.com> | 2014-03-05 18:58:17 -0600 |
---|---|---|
committer | Vinod Mangalpally <vinod.mang@rackspace.com> | 2014-03-05 18:58:56 -0600 |
commit | 877055aca77cc17f701fb2f6665cdd6ef420337f (patch) | |
tree | f8f2520c0110a9f559e2fcfbdbf85cf5759788c1 | |
parent | 57d24f3858e29988f8d1d8bd234cb6f6086b3ec5 (diff) | |
download | designate-877055aca77cc17f701fb2f6665cdd6ef420337f.tar.gz |
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
-rw-r--r-- | designate/api/v2/patches.py | 6 | ||||
-rw-r--r-- | designate/exceptions.py | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/designate/api/v2/patches.py b/designate/api/v2/patches.py index 1f0bf8ad..563401f1 100644 --- a/designate/api/v2/patches.py +++ b/designate/api/v2/patches.py @@ -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') diff --git a/designate/exceptions.py b/designate/exceptions.py index 183e531b..c2cdd42a 100644 --- a/designate/exceptions.py +++ b/designate/exceptions.py @@ -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' |