From 13a523e008f10cb6ed88690a47c79f329b8d500d Mon Sep 17 00:00:00 2001 From: zhuli Date: Mon, 24 Jul 2017 11:34:08 +0800 Subject: [PATCH] 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 --- sahara/utils/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sahara/utils/api.py b/sahara/utils/api.py index 3cb4f3e3..bb5370dc 100644 --- a/sahara/utils/api.py +++ b/sahara/utils/api.py @@ -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']