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:
parent
c83983f594
commit
13a523e008
@ -218,7 +218,8 @@ def render(res=None, resp_type=None, status=None, name=None, **kwargs):
|
|||||||
resp_type = RT_JSON
|
resp_type = RT_JSON
|
||||||
serializer = wsgi.JSONDictSerializer()
|
serializer = wsgi.JSONDictSerializer()
|
||||||
else:
|
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)
|
body = serializer.serialize(res)
|
||||||
resp_type = str(resp_type)
|
resp_type = str(resp_type)
|
||||||
@ -243,8 +244,8 @@ def request_data():
|
|||||||
if not content_type or content_type in RT_JSON:
|
if not content_type or content_type in RT_JSON:
|
||||||
deserializer = wsgi.JSONDeserializer()
|
deserializer = wsgi.JSONDeserializer()
|
||||||
else:
|
else:
|
||||||
abort_and_log(400,
|
raise ex.InvalidDataException(
|
||||||
_("Content type '%s' isn't supported") % content_type)
|
_("Content type '%s' isn't supported") % content_type)
|
||||||
|
|
||||||
# parsed request data to avoid unwanted re-parsings
|
# parsed request data to avoid unwanted re-parsings
|
||||||
parsed_data = deserializer.deserialize(flask.request.data)['body']
|
parsed_data = deserializer.deserialize(flask.request.data)['body']
|
||||||
|
Loading…
Reference in New Issue
Block a user