From b03181363bd78ab0934af3badd9b4845e454fbb3 Mon Sep 17 00:00:00 2001 From: Wouter Van Hemel Date: Wed, 4 Sep 2013 12:15:32 +0300 Subject: [PATCH] Add a non-decorator version of the error handler register function The main application object has a register_error_handler function which mirrors the decorator's functionality. According to the principle of least surprise, make sure blueprints also have this convenience function. --- flask/blueprints.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/flask/blueprints.py b/flask/blueprints.py index d45fd062..2b64c1f9 100644 --- a/flask/blueprints.py +++ b/flask/blueprints.py @@ -399,3 +399,14 @@ class Blueprint(_PackageBoundObject): self.name, code_or_exception, f)) return f return decorator + + def register_error_handler(self, code_or_exception, f): + """Non-decorator version of the :meth:`errorhandler` error attach + function, akin to the :meth:`~flask.Flask.register_error_handler` + application-wide function of the :class:`~flask.Flask` object but + for error handlers limited to this blueprint. + + .. versionadded:: 0.11 + """ + self.record_once(lambda s: s.app._register_error_handler( + self.name, code_or_exception, f))