Bad request exception for unsupported content type

Request without 'content-type: application/json' specified will
return '500 Internal Server Error', it should return more reasonable
'400 Bad Request'.

Change-Id: I45fe78c6c29257cac7cf4f8711d95350b6f8bf58
Closes-Bug: 1705665
This commit is contained in:
zhuli 2017-07-24 11:34:08 +08:00
parent c83983f594
commit 13a523e008
1 changed files with 4 additions and 3 deletions

View File

@ -218,7 +218,8 @@ def render(res=None, resp_type=None, status=None, name=None, **kwargs):
resp_type = RT_JSON
serializer = wsgi.JSONDictSerializer()
else:
abort_and_log(400, _("Content type '%s' isn't supported") % resp_type)
raise ex.InvalidDataException(
_("Content type '%s' isn't supported") % resp_type)
body = serializer.serialize(res)
resp_type = str(resp_type)
@ -243,8 +244,8 @@ def request_data():
if not content_type or content_type in RT_JSON:
deserializer = wsgi.JSONDeserializer()
else:
abort_and_log(400,
_("Content type '%s' isn't supported") % content_type)
raise ex.InvalidDataException(
_("Content type '%s' isn't supported") % content_type)
# parsed request data to avoid unwanted re-parsings
parsed_data = deserializer.deserialize(flask.request.data)['body']