Browse Source

set description for trap as well as debug

test for key error description
pull/2348/head
David Lord 8 years ago
parent
commit
42905b8a55
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
  1. 4
      flask/app.py
  2. 7
      tests/test_basic.py

4
flask/app.py

@ -1583,9 +1583,9 @@ class Flask(_PackageBoundObject):
# MultiDict passes the key to the exception, but that's ignored # MultiDict passes the key to the exception, but that's ignored
# when generating the response message. Set an informative # when generating the response message. Set an informative
# description for key errors in debug mode. # description for key errors in debug mode or when trapping errors.
if ( if (
self.debug self.debug or self.config['TRAP_BAD_REQUEST_ERRORS']
and isinstance(e, BadRequestKeyError) and isinstance(e, BadRequestKeyError)
# only set it if it's still the default description # only set it if it's still the default description
and e.description is BadRequestKeyError.description and e.description is BadRequestKeyError.description

7
tests/test_basic.py

@ -975,12 +975,17 @@ def test_trapping_of_bad_request_key_errors(app, client):
def fail(): def fail():
flask.request.form['missing_key'] flask.request.form['missing_key']
assert client.get('/fail').status_code == 400 rv = client.get('/fail')
assert rv.status_code == 400
assert b'missing_key' not in rv.data
app.config['TRAP_BAD_REQUEST_ERRORS'] = True app.config['TRAP_BAD_REQUEST_ERRORS'] = True
with pytest.raises(KeyError) as e: with pytest.raises(KeyError) as e:
client.get("/fail") client.get("/fail")
assert e.errisinstance(BadRequest) assert e.errisinstance(BadRequest)
assert 'missing_key' in e.value.description
def test_trapping_of_all_http_exceptions(app, client): def test_trapping_of_all_http_exceptions(app, client):

Loading…
Cancel
Save