Removed incorrect JSON exception subclasses
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent eb023bc · Browse files · 4 files·+11 added−73 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+11 added−73 removed
- other:+11 added−73 removed
Provenance
- Commit
4c27f7a- Tree
5653f02- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
eb023bc
4 files changed+11 added−73 removed
modified:flask/testsuite/helpers.py+1 added-13 removed
33 unmodified lines34 def test_json_bad_requests(self):35 app = flask.Flask(__name__)36 @app.route('/json', methods=['POST'])37 def return_json():38- return unicode(flask.request.json)38+ return flask.jsonify(foo=unicode(flask.request.json))39 c = app.test_client()40 rv = c.post('/json', data='malformed', content_type='application/json')41 self.assert_equal(rv.status_code, 400)42 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-43 def test_json_body_encoding(self):44 app = flask.Flask(__name__)45 app.testing = True46 @app.route('/')475 unmodified linesdeleted:flask/exceptions.py-48 removed
1-# -*- coding: utf-8 -*-2-"""3- flask.exceptions4- ~~~~~~~~~~~~5-6- Flask specific additions to :class:`~werkzeug.exceptions.HTTPException`7-8- :copyright: (c) 2011 by Armin Ronacher.9- :license: BSD, see LICENSE for more details.10-"""11-from werkzeug.exceptions import HTTPException, BadRequest12-from . import json13-14-15-class JSONHTTPException(HTTPException):16- """A base class for HTTP exceptions with ``Content-Type:17- application/json``.18-19- The ``description`` attribute of this class must set to a string (*not* an20- HTML string) which describes the error.21-22- """23-24- def get_body(self, environ):25- """Overrides :meth:`werkzeug.exceptions.HTTPException.get_body` to26- return the description of this error in JSON format instead of HTML.27-28- """29- return json.dumps(dict(description=self.get_description(environ)))30-31- def get_headers(self, environ):32- """Returns a list of headers including ``Content-Type:33- application/json``.34-35- """36- return [('Content-Type', 'application/json')]37-38-39-class JSONBadRequest(JSONHTTPException, BadRequest):40- """Represents an HTTP ``400 Bad Request`` error whose body contains an41- error message in JSON format instead of HTML format (as in the superclass).42- """43-44- #: The description of the error which occurred as a string.45- description = (46- 'The browser (or proxy) sent a request that this server could not '47- 'understand.'48- )modified:flask/wrappers.py+7 added-12 removed
9 unmodified lines10 """11 12 from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase13 from werkzeug.utils import cached_property14+from werkzeug.exceptions import BadRequest15 15-from .exceptions import JSONBadRequest16 from .debughelpers import attach_enctype_error_multidict17 from . import json18 from .globals import _request_ctx_stack19 86 unmodified lines106 107 def on_json_loading_failed(self, e):108 """Called if decoding of the JSON data failed. The return value of109 this method is used by :attr:`json` when an error occurred. The default110- implementation raises a :class:`JSONBadRequest`, which is a subclass of111- :class:`~werkzeug.exceptions.BadRequest` which sets the112- ``Content-Type`` to ``application/json`` and provides a JSON-formatted113- error description::110+ implementation just raises a :class:`BadRequest` exception.111 115- {"description": "The browser (or proxy) sent a request that \116- this server could not understand."}112+ .. versionchanged:: 0.10113+ Removed buggy previous behavior of generating a random JSON114+ response. If you want that behavior back you can trivially115+ add it by subclassing.116 118- .. versionchanged:: 0.9119- Return a :class:`JSONBadRequest` instead of a120- :class:`~werkzeug.exceptions.BadRequest` by default.121-117 .. versionadded:: 0.8118 """124- raise JSONBadRequest()119+ raise BadRequest()120 121 def _load_form_data(self):122 RequestBase._load_form_data(self)123 18 unmodified linesmodified:CHANGES+3 added
52 unmodified lines53 to work better with Google Chrome.54 - Added `message_flashed` signal that simplifies flashing testing.55 - Added support for copying of request contexts for better working with56 greenlets.57+- Removed custom JSON HTTP exception subclasses. If you were relying on them58+ you can reintroduce them again yourself trivially. Using them however is59+ strongly discouraged as the interface was flawed.60 61 Version 0.962 -----------63 365 unmodified lines