From acac64e36a046cebae07bee7f3e8106b4a80288a Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 8 Aug 2011 21:46:53 +0200 Subject: [PATCH] Don't only catch BadRequest key errors but all bad request errors. --- docs/config.rst | 14 ++++++++------ flask/app.py | 8 ++++---- tests/flask_tests.py | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index 4995ee84..f50e3180 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -89,13 +89,15 @@ The following configuration values are used internally by Flask: helpful for hairy debugging situations where you have to find out where an HTTP exception is coming from. -``TRAP_BAD_REQUEST_KEY_ERRORS`` Werkzeug's internal data structures that +``TRAP_BAD_REQUEST_ERRORS`` Werkzeug's internal data structures that deal with request specific data will raise special key errors that are also - bad request exceptions. By default - these will be converted into 400 - responses which however can make - debugging some issues harder. If this + bad request exceptions. Likewise many + operations can implicitly fail with a + BadRequest exception for consistency. + Since it's nice for debugging to know + why exactly it failed this flag can be + used to debug those situations. If this config is set to ``True`` you will get a regular traceback instead. ================================= ========================================= @@ -132,7 +134,7 @@ The following configuration values are used internally by Flask: ``PROPAGATE_EXCEPTIONS``, ``PRESERVE_CONTEXT_ON_EXCEPTION`` .. versionadded:: 0.8 - ``TRAP_BAD_REQUEST_KEY_ERRORS``, ``TRAP_HTTP_EXCEPTIONS`` + ``TRAP_BAD_REQUEST_ERRORS``, ``TRAP_HTTP_EXCEPTIONS`` Configuring from Files ---------------------- diff --git a/flask/app.py b/flask/app.py index 8995c511..009841f8 100644 --- a/flask/app.py +++ b/flask/app.py @@ -216,7 +216,7 @@ class Flask(_PackageBoundObject): 'LOGGER_NAME': None, 'SERVER_NAME': None, 'MAX_CONTENT_LENGTH': None, - 'TRAP_BAD_REQUEST_KEY_ERRORS': False, + 'TRAP_BAD_REQUEST_ERRORS': False, 'TRAP_HTTP_EXCEPTIONS': False }) @@ -1054,7 +1054,7 @@ class Flask(_PackageBoundObject): def trap_http_exception(self, e): """Checks if an HTTP exception should be trapped or not. By default this will return `False` for all exceptions except for a bad request - key error if ``TRAP_BAD_REQUEST_KEY_ERRORS`` is set to `True`. It + key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to `True`. It also returns `True` if ``TRAP_HTTP_EXCEPTIONS`` is set to `True`. This is called for all HTTP exceptions raised by a view function. @@ -1067,8 +1067,8 @@ class Flask(_PackageBoundObject): """ if self.config['TRAP_HTTP_EXCEPTIONS']: return True - if self.config['TRAP_BAD_REQUEST_KEY_ERRORS']: - return isinstance(e, BadRequest) and isinstance(e, LookupError) + if self.config['TRAP_BAD_REQUEST_ERRORS']: + return isinstance(e, BadRequest) return False def handle_user_exception(self, e): diff --git a/tests/flask_tests.py b/tests/flask_tests.py index 467381eb..5e592710 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -601,7 +601,7 @@ class BasicFunctionalityTestCase(unittest.TestCase): c = app.test_client() assert c.get('/fail').status_code == 400 - app.config['TRAP_BAD_REQUEST_KEY_ERRORS'] = True + app.config['TRAP_BAD_REQUEST_ERRORS'] = True c = app.test_client() try: c.get('/fail')