forked from orbit-oss/flask
Added documentation in update document for new error handling
This commit is contained in:
parent
f5ec9952de
commit
1f31ec4bea
2 changed files with 36 additions and 0 deletions
|
|
@ -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
|
||||
-----------
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue