Skip to content
Myr

set description for trap as well as debug

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

test for key error description

authored by David Lord · committed by David Lord · parent 045dcca · Browse files · 2 files+8 added−3 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+8 added−3 removed

  • tests:+6 added−1 removed
  • other:+2 added−2 removed

2 files+8 added−3 removed

modified:flask/app.py+2 added-2 removed
1581 unmodified lines
1582 # trap_http_exception method so that's their fault then.15831584 # MultiDict passes the key to the exception, but that's ignored1585 # when generating the response message. Set an informative1586 # description for key errors in debug mode.1586 # description for key errors in debug mode or when trapping errors.1587 if (1588 self.debug1588 self.debug or self.config['TRAP_BAD_REQUEST_ERRORS']1589 and isinstance(e, BadRequestKeyError)1590 # only set it if it's still the default description1591 and e.description is BadRequestKeyError.description1592 ):
548 unmodified lines
modified:tests/test_basic.py+6 added-1 removed
973 unmodified lines
974 @app.route('/fail')975 def fail():976 flask.request.form['missing_key']977978 rv = client.get('/fail')978 assert client.get('/fail').status_code == 400979 assert rv.status_code == 400980 assert b'missing_key' not in rv.data981982 app.config['TRAP_BAD_REQUEST_ERRORS'] = True983984 with pytest.raises(KeyError) as e:985 client.get("/fail")986987 assert e.errisinstance(BadRequest)988 assert 'missing_key' in e.value.description989990991def test_trapping_of_all_http_exceptions(app, client):992 app.config['TRAP_HTTP_EXCEPTIONS'] = True
830 unmodified lines