Don't only catch BadRequest key errors but all bad request errors.
This commit is contained in:
parent
505cd663cd
commit
acac64e36a
3 changed files with 13 additions and 11 deletions
|
|
@ -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
|
||||
----------------------
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue