Skip to content
Myr

Merge pull request #859 from wvh/register_error_handler

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

Add a non-decorator version of the error handler register function

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 3fd40e8, 079ae20 · Browse files · 2 files+44 added−0 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+44 added−0 removed

  • other:+44 added−0 removed

2 files+44 added−0 removed

modified:flask/testsuite/blueprints.py+33 added
294 unmodified lines
295 self.assert_equal(c.get('/frontend-no').data, b'frontend says no')296 self.assert_equal(c.get('/backend-no').data, b'backend says no')297 self.assert_equal(c.get('/what-is-a-sideend').data, b'application itself says no')298299 def test_blueprint_specific_user_error_handling(self):300 class MyDecoratorException(Exception):301 pass302 class MyFunctionException(Exception):303 pass304305 blue = flask.Blueprint('blue', __name__)306307 @blue.errorhandler(MyDecoratorException)308 def my_decorator_exception_handler(e):309 self.assert_true(isinstance(e, MyDecoratorException))310 return 'boom'311312 def my_function_exception_handler(e):313 self.assert_true(isinstance(e, MyFunctionException))314 return 'bam'315 blue.register_error_handler(MyFunctionException, my_function_exception_handler)316317 @blue.route('/decorator')318 def blue_deco_test():319 raise MyDecoratorException()320 @blue.route('/function')321 def blue_func_test():322 raise MyFunctionException()323324 app = flask.Flask(__name__)325 app.register_blueprint(blue)326327 c = app.test_client()328329 self.assert_equal(c.get('/decorator').data, b'boom')330 self.assert_equal(c.get('/function').data, b'bam')331332 def test_blueprint_url_definitions(self):333 bp = flask.Blueprint('test', __name__)334335 @bp.route('/foo', defaults={'baz': 42})
488 unmodified lines
modified:flask/blueprints.py+11 added
397 unmodified lines
398 self.record_once(lambda s: s.app._register_error_handler(399 self.name, code_or_exception, f))400 return f401 return decorator402403 def register_error_handler(self, code_or_exception, f):404 """Non-decorator version of the :meth:`errorhandler` error attach405 function, akin to the :meth:`~flask.Flask.register_error_handler`406 application-wide function of the :class:`~flask.Flask` object but407 for error handlers limited to this blueprint.408409 .. versionadded:: 0.11410 """411 self.record_once(lambda s: s.app._register_error_handler(412 self.name, code_or_exception, f))