Skip to content
Myr

Don't only catch BadRequest key errors but all bad request errors.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 505cd66 · Browse files · 3 files+13 added−11 removed
This commit

State

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

Diff stats

3 files+13 added−11 removed

  • tests:+1 added−1 removed
  • other:+12 added−10 removed

3 files+13 added−11 removed

modified:docs/config.rst+8 added-6 removed
87 unmodified lines
88 through the exception stack. This is89 helpful for hairy debugging situations90 where you have to find out where an HTTP91 exception is coming from.92``TRAP_BAD_REQUEST_KEY_ERRORS`` Werkzeug's internal data structures that92``TRAP_BAD_REQUEST_ERRORS`` Werkzeug's internal data structures that93 deal with request specific data will94 raise special key errors that are also95 bad request exceptions. By default96 these will be converted into 40097 responses which however can make98 debugging some issues harder. If this95 bad request exceptions. Likewise many96 operations can implicitly fail with a97 BadRequest exception for consistency.98 Since it's nice for debugging to know99 why exactly it failed this flag can be100 used to debug those situations. If this101 config is set to ``True`` you will get102 a regular traceback instead.103================================= =========================================104
28 unmodified lines
133.. versionadded:: 0.7134 ``PROPAGATE_EXCEPTIONS``, ``PRESERVE_CONTEXT_ON_EXCEPTION``135136.. versionadded:: 0.8135 ``TRAP_BAD_REQUEST_KEY_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``137 ``TRAP_BAD_REQUEST_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``138139Configuring from Files140----------------------141
128 unmodified lines
modified:flask/app.py+4 added-4 removed
214 unmodified lines
215 'USE_X_SENDFILE': False,216 'LOGGER_NAME': None,217 'SERVER_NAME': None,218 'MAX_CONTENT_LENGTH': None,219 'TRAP_BAD_REQUEST_KEY_ERRORS': False,219 'TRAP_BAD_REQUEST_ERRORS': False,220 'TRAP_HTTP_EXCEPTIONS': False221 })222223 #: The rule object to use for URL rules created. This is used by
829 unmodified lines
10531054 def trap_http_exception(self, e):1055 """Checks if an HTTP exception should be trapped or not. By default1056 this will return `False` for all exceptions except for a bad request1057 key error if ``TRAP_BAD_REQUEST_KEY_ERRORS`` is set to `True`. It1057 key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to `True`. It1058 also returns `True` if ``TRAP_HTTP_EXCEPTIONS`` is set to `True`.10591060 This is called for all HTTP exceptions raised by a view function.1061 If it returns `True` for any exception the error handler for this
4 unmodified lines
1066 .. versionadded:: 0.81067 """1068 if self.config['TRAP_HTTP_EXCEPTIONS']:1069 return True1070 if self.config['TRAP_BAD_REQUEST_KEY_ERRORS']:1071 return isinstance(e, BadRequest) and isinstance(e, LookupError)1070 if self.config['TRAP_BAD_REQUEST_ERRORS']:1071 return isinstance(e, BadRequest)1072 return False10731074 def handle_user_exception(self, e):1075 """This method is called whenever an exception occurs that should be
358 unmodified lines
modified:tests/flask_tests.py+1 added-1 removed
599 unmodified lines
600 flask.request.form['missing_key']601 c = app.test_client()602 assert c.get('/fail').status_code == 400603604 app.config['TRAP_BAD_REQUEST_KEY_ERRORS'] = True604 app.config['TRAP_BAD_REQUEST_ERRORS'] = True605 c = app.test_client()606 try:607 c.get('/fail')608 except KeyError, e:
1468 unmodified lines