Skip to content

Commit 4c27f7a

Browse files
committed
Removed incorrect JSON exception subclasses
1 parent eb023bc commit 4c27f7a

File tree

4 files changed

+11
-73
lines changed

4 files changed

+11
-73
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Release date to be decided.
5454
- Added `message_flashed` signal that simplifies flashing testing.
5555
- Added support for copying of request contexts for better working with
5656
greenlets.
57+
- Removed custom JSON HTTP exception subclasses. If you were relying on them
58+
you can reintroduce them again yourself trivially. Using them however is
59+
strongly discouraged as the interface was flawed.
5760

5861
Version 0.9
5962
-----------

flask/exceptions.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

flask/testsuite/helpers.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,11 @@ def test_json_bad_requests(self):
3535
app = flask.Flask(__name__)
3636
@app.route('/json', methods=['POST'])
3737
def return_json():
38-
return unicode(flask.request.json)
38+
return flask.jsonify(foo=unicode(flask.request.json))
3939
c = app.test_client()
4040
rv = c.post('/json', data='malformed', content_type='application/json')
4141
self.assert_equal(rv.status_code, 400)
4242

43-
def test_json_bad_requests_content_type(self):
44-
app = flask.Flask(__name__)
45-
@app.route('/json', methods=['POST'])
46-
def return_json():
47-
return unicode(flask.request.json)
48-
c = app.test_client()
49-
rv = c.post('/json', data='malformed', content_type='application/json')
50-
self.assert_equal(rv.status_code, 400)
51-
self.assert_equal(rv.mimetype, 'application/json')
52-
self.assert_('description' in flask.json.loads(rv.data))
53-
self.assert_('<p>' not in flask.json.loads(rv.data)['description'])
54-
5543
def test_json_body_encoding(self):
5644
app = flask.Flask(__name__)
5745
app.testing = True

flask/wrappers.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase
1313
from werkzeug.utils import cached_property
14+
from werkzeug.exceptions import BadRequest
1415

15-
from .exceptions import JSONBadRequest
1616
from .debughelpers import attach_enctype_error_multidict
1717
from . import json
1818
from .globals import _request_ctx_stack
@@ -107,21 +107,16 @@ def json(self):
107107
def on_json_loading_failed(self, e):
108108
"""Called if decoding of the JSON data failed. The return value of
109109
this method is used by :attr:`json` when an error occurred. The default
110-
implementation raises a :class:`JSONBadRequest`, which is a subclass of
111-
:class:`~werkzeug.exceptions.BadRequest` which sets the
112-
``Content-Type`` to ``application/json`` and provides a JSON-formatted
113-
error description::
110+
implementation just raises a :class:`BadRequest` exception.
114111
115-
{"description": "The browser (or proxy) sent a request that \
116-
this server could not understand."}
117-
118-
.. versionchanged:: 0.9
119-
Return a :class:`JSONBadRequest` instead of a
120-
:class:`~werkzeug.exceptions.BadRequest` by default.
112+
.. versionchanged:: 0.10
113+
Removed buggy previous behavior of generating a random JSON
114+
response. If you want that behavior back you can trivially
115+
add it by subclassing.
121116
122117
.. versionadded:: 0.8
123118
"""
124-
raise JSONBadRequest()
119+
raise BadRequest()
125120

126121
def _load_form_data(self):
127122
RequestBase._load_form_data(self)

0 commit comments

Comments
 (0)