Browse Source

Added documentation in update document for new error handling

pull/262/head
Armin Ronacher 14 years ago
parent
commit
1f31ec4bea
  1. 27
      docs/upgrading.rst
  2. 9
      flask/app.py

27
docs/upgrading.rst

@ -91,6 +91,33 @@ handling::
# and here it's gone
Manual Error Handler Attaching
``````````````````````````````
While it is still possible to attach error handlers to
:attr:`Flask.error_handlers` it's discouraged to do so and in fact
deprecated. In generaly we no longer recommend custom error handler
attaching via assignments to the underlying dictionary due to the more
complex internal handling to support arbitrary exception classes and
blueprints. See :meth:`Flask.errorhandler` for more information.
The proper upgrade is to change this::
app.error_handlers[403] = handle_error
Into this::
app.register_error_handler(403, handle_error)
Alternatively you should just attach the function with a decorator::
@app.errorhandler(403)
def handle_error(e):
...
(Note that :meth:`register_error_handler` is new in Flask 0.7)
Version 0.6
-----------

9
flask/app.py

@ -822,6 +822,15 @@ class Flask(_PackageBoundObject):
return f
return decorator
def register_error_handler(self, code_or_exception, f):
"""Alternative error attach function to the :meth:`errorhandler`
decorator that is more straightforward to use for non decorator
usage.
.. versionadded:: 0.7
"""
self._register_error_handler(None, code_or_exception, f)
def _register_error_handler(self, key, code_or_exception, f):
if isinstance(code_or_exception, HTTPException):
code_or_exception = code_or_exception.code

Loading…
Cancel
Save