forked from orbit-oss/flask
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
|
helpful for hairy debugging situations
|
||||||
where you have to find out where an HTTP
|
where you have to find out where an HTTP
|
||||||
exception is coming from.
|
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
|
deal with request specific data will
|
||||||
raise special key errors that are also
|
raise special key errors that are also
|
||||||
bad request exceptions. By default
|
bad request exceptions. Likewise many
|
||||||
these will be converted into 400
|
operations can implicitly fail with a
|
||||||
responses which however can make
|
BadRequest exception for consistency.
|
||||||
debugging some issues harder. If this
|
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
|
config is set to ``True`` you will get
|
||||||
a regular traceback instead.
|
a regular traceback instead.
|
||||||
================================= =========================================
|
================================= =========================================
|
||||||
|
|
@ -132,7 +134,7 @@ The following configuration values are used internally by Flask:
|
||||||
``PROPAGATE_EXCEPTIONS``, ``PRESERVE_CONTEXT_ON_EXCEPTION``
|
``PROPAGATE_EXCEPTIONS``, ``PRESERVE_CONTEXT_ON_EXCEPTION``
|
||||||
|
|
||||||
.. versionadded:: 0.8
|
.. versionadded:: 0.8
|
||||||
``TRAP_BAD_REQUEST_KEY_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``
|
``TRAP_BAD_REQUEST_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``
|
||||||
|
|
||||||
Configuring from Files
|
Configuring from Files
|
||||||
----------------------
|
----------------------
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ class Flask(_PackageBoundObject):
|
||||||
'LOGGER_NAME': None,
|
'LOGGER_NAME': None,
|
||||||
'SERVER_NAME': None,
|
'SERVER_NAME': None,
|
||||||
'MAX_CONTENT_LENGTH': None,
|
'MAX_CONTENT_LENGTH': None,
|
||||||
'TRAP_BAD_REQUEST_KEY_ERRORS': False,
|
'TRAP_BAD_REQUEST_ERRORS': False,
|
||||||
'TRAP_HTTP_EXCEPTIONS': False
|
'TRAP_HTTP_EXCEPTIONS': False
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -1054,7 +1054,7 @@ class Flask(_PackageBoundObject):
|
||||||
def trap_http_exception(self, e):
|
def trap_http_exception(self, e):
|
||||||
"""Checks if an HTTP exception should be trapped or not. By default
|
"""Checks if an HTTP exception should be trapped or not. By default
|
||||||
this will return `False` for all exceptions except for a bad request
|
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`.
|
also returns `True` if ``TRAP_HTTP_EXCEPTIONS`` is set to `True`.
|
||||||
|
|
||||||
This is called for all HTTP exceptions raised by a view function.
|
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']:
|
if self.config['TRAP_HTTP_EXCEPTIONS']:
|
||||||
return True
|
return True
|
||||||
if self.config['TRAP_BAD_REQUEST_KEY_ERRORS']:
|
if self.config['TRAP_BAD_REQUEST_ERRORS']:
|
||||||
return isinstance(e, BadRequest) and isinstance(e, LookupError)
|
return isinstance(e, BadRequest)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def handle_user_exception(self, e):
|
def handle_user_exception(self, e):
|
||||||
|
|
|
||||||
|
|
@ -601,7 +601,7 @@ class BasicFunctionalityTestCase(unittest.TestCase):
|
||||||
c = app.test_client()
|
c = app.test_client()
|
||||||
assert c.get('/fail').status_code == 400
|
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()
|
c = app.test_client()
|
||||||
try:
|
try:
|
||||||
c.get('/fail')
|
c.get('/fail')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue