Skip to content
Myr

Merge pull request #1360 from keyanp/issue1317

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add exception details to response

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents e527c17, 7b08035 · Browse files · 2 files+27 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−1 removed

  • tests:+24 added−0 removed
  • other:+3 added−1 removed

2 files+27 added−1 removed

modified:flask/wrappers.py+3 added-1 removed
13 unmodified lines
1415from . import json16from .globals import _request_ctx_stack171818_missing = object()192021def _get_data(req, cache):
151 unmodified lines
173 add it by subclassing.174175 .. versionadded:: 0.8176 """177 ctx = _request_ctx_stack.top178 if ctx is not None and ctx.app.config.get('DEBUG', False):179 raise BadRequest('Failed to decode JSON object: {0}'.format(e))180 raise BadRequest()181182 def _load_form_data(self):183 RequestBase._load_form_data(self)
20 unmodified lines
modified:tests/test_helpers.py+24 added
47 unmodified lines
48 rv = c.get(url)49 assert rv.mimetype == 'application/json'50 assert flask.json.loads(rv.data)['x'] == http_date(d.timetuple())5152 def test_post_empty_json_adds_exception_to_response_content_in_debug(self):53 app = flask.Flask(__name__)54 app.config['DEBUG'] = True55 @app.route('/json', methods=['POST'])56 def post_json():57 flask.request.get_json()58 return None59 c = app.test_client()60 rv = c.post('/json', data=None, content_type='application/json')61 assert rv.status_code == 40062 assert b'Failed to decode JSON object' in rv.data6364 def test_post_empty_json_wont_add_exception_to_response_if_no_debug(self):65 app = flask.Flask(__name__)66 app.config['DEBUG'] = False67 @app.route('/json', methods=['POST'])68 def post_json():69 flask.request.get_json()70 return None71 c = app.test_client()72 rv = c.post('/json', data=None, content_type='application/json')73 assert rv.status_code == 40074 assert b'Failed to decode JSON object' not in rv.data7576 def test_json_bad_requests(self):77 app = flask.Flask(__name__)78 @app.route('/json', methods=['POST'])79 def return_json():
601 unmodified lines