Skip to content
Myr

Do not handle RoutingExceptions with app error handlers

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

authored by Jimmy Jia · committed by David Lord · parent 38a3918 · Browse files · 2 files+13 added−1 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+13 added−1 removed

  • tests:+5 added−0 removed
  • other:+8 added−1 removed

2 files+13 added−1 removed

modified:flask/app.py+8 added-1 removed
18 unmodified lines
1920from werkzeug.datastructures import Headers, ImmutableDict21from werkzeug.exceptions import BadRequest, BadRequestKeyError, HTTPException, \22 InternalServerError, MethodNotAllowed, default_exceptions23from werkzeug.routing import BuildError, Map, RequestRedirect, Rule23from werkzeug.routing import BuildError, Map, RequestRedirect, \24 RoutingException, Rule2526from . import cli, json27from ._compat import integer_types, reraise, string_types, text_type28from .config import Config, ConfigAttribute
1609 unmodified lines
1638 # those unchanged as errors1639 if e.code is None:1640 return e16411642 # RoutingExceptions such as RequestRedirects are special exceptions1643 # used to trigger routing actions such as redirects, and also behave1644 # like proxy exceptions. We return these unchanged as well.1645 if isinstance(e, RoutingException):1646 return e16471648 handler = self._find_error_handler(e)1649 if handler is None:1650 return e1651 return handler(e)
673 unmodified lines
modified:tests/test_user_error_handler.py+5 added
182 unmodified lines
183 @app.route('/forbidden')184 def forbidden():185 raise Forbidden()186187 @app.route('/slash/')188 def slash():189 return ''190191 app.register_blueprint(bp, url_prefix='/bp')192193 c = app.test_client()194 assert c.get('/bp/undefined').data == b'bp-default'195 assert c.get('/bp/forbidden').data == b'bp-forbidden'196 assert c.get('/undefined').data == b'default'197 assert c.get('/forbidden').data == b'forbidden'198 assert c.get('/slash').location.endswith('/slash/')199200