Path 1: 52 calls (1.0)

403 (9) AppError def (7) BlueprintError def (7) 500 (7) Exception def (3) Forbidden def (3) HTTPException def (3) 404 (2) test_user_error_handling.

Scaffold.errorhandler..decorator def (52)

1@setupmethod
2    def errorhandler(
3        self, code_or_exception: type[Exception] | int
4    ) -> t.Callable[[T_error_handler], T_error_handler]:
5        """Register a function to handle errors by code or exception class.
6
7        A decorator that is used to register a function given an
8        error code.  Example::
9
10            @app.errorhandler(404)
11            def page_not_found(error):
12                return 'This page does not exist', 404
13
14        You can also register handlers for arbitrary exceptions::
15
16            @app.errorhandler(DatabaseError)
17            def special_exception_handler(error):
18                return 'Database connection failed', 500
19
20        This is available on both app and blueprint objects. When used on an app, this
21        can handle errors from every request. When used on a blueprint, this can handle
22        errors from requests that the blueprint handles. To register with a blueprint
23        and affect every request, use :meth:`.Blueprint.app_errorhandler`.
24
25        .. versionadded:: 0.7
26            Use :meth:`register_error_handler` instead of modifying
27            :attr:`error_handler_spec` directly, for application wide error
28            handlers.
29
30        .. versionadded:: 0.7
31           One can now additionally also register custom exception types
32           that do not necessarily have to be a subclass of the
33           :class:`~werkzeug.exceptions.HTTPException` class.
34
35        :param code_or_exception: the code as integer for the handler, or
36                                  an arbitrary exception
37        """
38
39        def decorator(f: T_error_handler) -> T_error_handler:
40            self.register_error_handler(code_or_exception, f)
41            return f
42
43        return decorator