From 91b27cc213f282b5f05908875ecdc35651fcb5d8 Mon Sep 17 00:00:00 2001 From: Roman Bodnarchuk Date: Thu, 8 May 2014 06:48:05 -0400 Subject: [PATCH] Fix 500 error if request body is not JSON object In `JsonBodyMiddleware` we expect POST body to be a JSON dictionary, and failed with 500 error if body was a valid JSON, but not a dictionary. Additional check was added along with a test for described case. Change-Id: I08ae3c8fa4eb53b67604d8b8791ca19d9c1682e6 Closes-Bug: #1316657 --- core.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core.py b/core.py index 7773f3cc..4bc1927a 100644 --- a/core.py +++ b/core.py @@ -131,6 +131,11 @@ class JsonBodyMiddleware(wsgi.Middleware): if not params_parsed: params_parsed = {} + if not isinstance(params_parsed, dict): + e = exception.ValidationError(attribute='valid JSON object', + target='request body') + return wsgi.render_exception(e, request=request) + params = {} for k, v in six.iteritems(params_parsed): if k in ('self', 'context'):