Merge "HTTPBadRequest in v2 on malformed JSON request body."
This commit is contained in:
commit
24c072881a
@ -455,7 +455,11 @@ class JSONRequestDeserializer(object):
|
||||
return False
|
||||
|
||||
def from_json(self, datastring):
|
||||
return json.loads(datastring)
|
||||
try:
|
||||
return json.loads(datastring)
|
||||
except ValueError:
|
||||
msg = _('Malformed JSON in request body.')
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
def default(self, request):
|
||||
if self.has_body(request):
|
||||
|
@ -177,6 +177,11 @@ class JSONRequestDeserializerTest(test_utils.BaseTestCase):
|
||||
actual = wsgi.JSONRequestDeserializer().from_json(fixture)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_from_json_malformed(self):
|
||||
fixture = 'kjasdklfjsklajf'
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
wsgi.JSONRequestDeserializer().from_json, fixture)
|
||||
|
||||
def test_default_no_body(self):
|
||||
request = wsgi.Request.blank('/')
|
||||
actual = wsgi.JSONRequestDeserializer().default(request)
|
||||
|
Loading…
Reference in New Issue
Block a user