Method: flask.app.Flask.handle_exception
Calls: 35, Exceptions: 0, Paths: 5Back
Path 1: 15 calls (0.43)
TypeError (5) BadRequestKeyError (2) ZeroDivisionError (2) ValueError (1) BadRequest (1) NotFound (1) DebugFilesKeyError (1) FormDataRoutingRedirect (...
1def handle_exception(self, e: Exception) -> Response:
2 """Handle an exception that did not have an error handler
3 associated with it, or that was raised from an error handler.
4 This always causes a 500 ``InternalServerError``.
5
6 Always sends the :data:`got_request_exception` signal.
7
8 If :data:`PROPAGATE_EXCEPTIONS` is ``True``, such as in debug
9 mode, the error will be re-raised so that the debugger can
10 display it. Otherwise, the original exception is logged, and
11 an :exc:`~werkzeug.exceptions.InternalServerError` is returned.
12
13 If an error handler is registered for ``InternalServerError`` or
14 ``500``, it will be used. For consistency, the handler will
15 always receive the ``InternalServerError``. The original
16 unhandled exception is available as ``e.original_exception``.
17
18 .. versionchanged:: 1.1.0
19 Always passes the ``InternalServerError`` instance to the
20 handler, setting ``original_exception`` to the unhandled
21 error.
22
23 .. versionchanged:: 1.1.0
24 ``after_request`` functions and other finalization is done
25 even for the default 500 response when there is no handler.
26
27 .. versionadded:: 0.3
28 """
29 exc_info = sys.exc_info()
30 got_request_exception.send(self, _async_wrapper=self.ensure_sync, exception=e)
31 propagate = self.config["PROPAGATE_EXCEPTIONS"]
32
33 if propagate is None:
34 propagate = self.testing or self.debug
35
36 if propagate:
37 # Re-raise if called with an active exception, otherwise
38 # raise the passed in exception.
39 if exc_info[1] is e:
40 raise
41
42 raise e
43
44 self.log_exception(exc_info)
45 server_error: InternalServerError | ft.ResponseReturnValue
46 server_error = InternalServerError(original_exception=e)
47 handler = self._find_error_handler(server_error)
48
49 if handler is not None:
50 server_error = self.ensure_sync(handler)(server_error)
51
52 return self.finalize_request(server_error, from_error_handler=True)
Path 2: 8 calls (0.23)
ZeroDivisionError (5) Exception (2) test_session_error_pops_context.
Response (8)
1def handle_exception(self, e: Exception) -> Response:
2 """Handle an exception that did not have an error handler
3 associated with it, or that was raised from an error handler.
4 This always causes a 500 ``InternalServerError``.
5
6 Always sends the :data:`got_request_exception` signal.
7
8 If :data:`PROPAGATE_EXCEPTIONS` is ``True``, such as in debug
9 mode, the error will be re-raised so that the debugger can
10 display it. Otherwise, the original exception is logged, and
11 an :exc:`~werkzeug.exceptions.InternalServerError` is returned.
12
13 If an error handler is registered for ``InternalServerError`` or
14 ``500``, it will be used. For consistency, the handler will
15 always receive the ``InternalServerError``. The original
16 unhandled exception is available as ``e.original_exception``.
17
18 .. versionchanged:: 1.1.0
19 Always passes the ``InternalServerError`` instance to the
20 handler, setting ``original_exception`` to the unhandled
21 error.
22
23 .. versionchanged:: 1.1.0
24 ``after_request`` functions and other finalization is done
25 even for the default 500 response when there is no handler.
26
27 .. versionadded:: 0.3
28 """
29 exc_info = sys.exc_info()
30 got_request_exception.send(self, _async_wrapper=self.ensure_sync, exception=e)
31 propagate = self.config["PROPAGATE_EXCEPTIONS"]
32
33 if propagate is None:
34 propagate = self.testing or self.debug
35
36 if propagate:
37 # Re-raise if called with an active exception, otherwise
38 # raise the passed in exception.
39 if exc_info[1] is e:
40 raise
41
42 raise e
43
44 self.log_exception(exc_info)
45 server_error: InternalServerError | ft.ResponseReturnValue
46 server_error = InternalServerError(original_exception=e)
47 handler = self._find_error_handler(server_error)
48
49 if handler is not None:
50 server_error = self.ensure_sync(handler)(server_error)
51
52 return self.finalize_request(server_error, from_error_handler=True)
Path 3: 5 calls (0.14)
ZeroDivisionError (4) KeyError (1)
Response (5)
1def handle_exception(self, e: Exception) -> Response:
2 """Handle an exception that did not have an error handler
3 associated with it, or that was raised from an error handler.
4 This always causes a 500 ``InternalServerError``.
5
6 Always sends the :data:`got_request_exception` signal.
7
8 If :data:`PROPAGATE_EXCEPTIONS` is ``True``, such as in debug
9 mode, the error will be re-raised so that the debugger can
10 display it. Otherwise, the original exception is logged, and
11 an :exc:`~werkzeug.exceptions.InternalServerError` is returned.
12
13 If an error handler is registered for ``InternalServerError`` or
14 ``500``, it will be used. For consistency, the handler will
15 always receive the ``InternalServerError``. The original
16 unhandled exception is available as ``e.original_exception``.
17
18 .. versionchanged:: 1.1.0
19 Always passes the ``InternalServerError`` instance to the
20 handler, setting ``original_exception`` to the unhandled
21 error.
22
23 .. versionchanged:: 1.1.0
24 ``after_request`` functions and other finalization is done
25 even for the default 500 response when there is no handler.
26
27 .. versionadded:: 0.3
28 """
29 exc_info = sys.exc_info()
30 got_request_exception.send(self, _async_wrapper=self.ensure_sync, exception=e)
31 propagate = self.config["PROPAGATE_EXCEPTIONS"]
32
33 if propagate is None:
34 propagate = self.testing or self.debug
35
36 if propagate:
37 # Re-raise if called with an active exception, otherwise
38 # raise the passed in exception.
39 if exc_info[1] is e:
40 raise
41
42 raise e
43
44 self.log_exception(exc_info)
45 server_error: InternalServerError | ft.ResponseReturnValue
46 server_error = InternalServerError(original_exception=e)
47 handler = self._find_error_handler(server_error)
48
49 if handler is not None:
50 server_error = self.ensure_sync(handler)(server_error)
51
52 return self.finalize_request(server_error, from_error_handler=True)
Path 4: 5 calls (0.14)
KeyError (3) TestGenericHandlers.Custom (2)
Response (5)
1def handle_exception(self, e: Exception) -> Response:
2 """Handle an exception that did not have an error handler
3 associated with it, or that was raised from an error handler.
4 This always causes a 500 ``InternalServerError``.
5
6 Always sends the :data:`got_request_exception` signal.
7
8 If :data:`PROPAGATE_EXCEPTIONS` is ``True``, such as in debug
9 mode, the error will be re-raised so that the debugger can
10 display it. Otherwise, the original exception is logged, and
11 an :exc:`~werkzeug.exceptions.InternalServerError` is returned.
12
13 If an error handler is registered for ``InternalServerError`` or
14 ``500``, it will be used. For consistency, the handler will
15 always receive the ``InternalServerError``. The original
16 unhandled exception is available as ``e.original_exception``.
17
18 .. versionchanged:: 1.1.0
19 Always passes the ``InternalServerError`` instance to the
20 handler, setting ``original_exception`` to the unhandled
21 error.
22
23 .. versionchanged:: 1.1.0
24 ``after_request`` functions and other finalization is done
25 even for the default 500 response when there is no handler.
26
27 .. versionadded:: 0.3
28 """
29 exc_info = sys.exc_info()
30 got_request_exception.send(self, _async_wrapper=self.ensure_sync, exception=e)
31 propagate = self.config["PROPAGATE_EXCEPTIONS"]
32
33 if propagate is None:
34 propagate = self.testing or self.debug
35
36 if propagate:
37 # Re-raise if called with an active exception, otherwise
38 # raise the passed in exception.
39 if exc_info[1] is e:
40 raise
41
42 raise e
43
44 self.log_exception(exc_info)
45 server_error: InternalServerError | ft.ResponseReturnValue
46 server_error = InternalServerError(original_exception=e)
47 handler = self._find_error_handler(server_error)
48
49 if handler is not None:
50 server_error = self.ensure_sync(handler)(server_error)
51
52 return self.finalize_request(server_error, from_error_handler=True)
Path 5: 2 calls (0.06)
ValueError (1) ZeroDivisionError (1)
1def handle_exception(self, e: Exception) -> Response:
2 """Handle an exception that did not have an error handler
3 associated with it, or that was raised from an error handler.
4 This always causes a 500 ``InternalServerError``.
5
6 Always sends the :data:`got_request_exception` signal.
7
8 If :data:`PROPAGATE_EXCEPTIONS` is ``True``, such as in debug
9 mode, the error will be re-raised so that the debugger can
10 display it. Otherwise, the original exception is logged, and
11 an :exc:`~werkzeug.exceptions.InternalServerError` is returned.
12
13 If an error handler is registered for ``InternalServerError`` or
14 ``500``, it will be used. For consistency, the handler will
15 always receive the ``InternalServerError``. The original
16 unhandled exception is available as ``e.original_exception``.
17
18 .. versionchanged:: 1.1.0
19 Always passes the ``InternalServerError`` instance to the
20 handler, setting ``original_exception`` to the unhandled
21 error.
22
23 .. versionchanged:: 1.1.0
24 ``after_request`` functions and other finalization is done
25 even for the default 500 response when there is no handler.
26
27 .. versionadded:: 0.3
28 """
29 exc_info = sys.exc_info()
30 got_request_exception.send(self, _async_wrapper=self.ensure_sync, exception=e)
31 propagate = self.config["PROPAGATE_EXCEPTIONS"]
32
33 if propagate is None:
34 propagate = self.testing or self.debug
35
36 if propagate:
37 # Re-raise if called with an active exception, otherwise
38 # raise the passed in exception.
39 if exc_info[1] is e:
40 raise
41
42 raise e
43
44 self.log_exception(exc_info)
45 server_error: InternalServerError | ft.ResponseReturnValue
46 server_error = InternalServerError(original_exception=e)
47 handler = self._find_error_handler(server_error)
48
49 if handler is not None:
50 server_error = self.ensure_sync(handler)(server_error)
51
52 return self.finalize_request(server_error, from_error_handler=True)