forked from orbit-oss/flask
got_request_exception only sends unhandled exceptions
Co-authored-by: David Lord <davidism@gmail.com>
This commit is contained in:
parent
6355f12176
commit
451c1f87f3
1 changed files with 22 additions and 8 deletions
30
docs/api.rst
30
docs/api.rst
|
|
@ -440,18 +440,32 @@ The following signals exist in Flask:
|
||||||
|
|
||||||
.. data:: got_request_exception
|
.. data:: got_request_exception
|
||||||
|
|
||||||
This signal is sent when an exception happens during request processing.
|
This signal is sent when an unhandled exception happens during
|
||||||
It is sent *before* the standard exception handling kicks in and even
|
request processing, including when debugging. The exception is
|
||||||
in debug mode, where no exception handling happens. The exception
|
passed to the subscriber as ``exception``.
|
||||||
itself is passed to the subscriber as `exception`.
|
|
||||||
|
|
||||||
Example subscriber::
|
This signal is not sent for
|
||||||
|
:exc:`~werkzeug.exceptions.HTTPException`, or other exceptions that
|
||||||
|
have error handlers registered, unless the exception was raised from
|
||||||
|
an error handler.
|
||||||
|
|
||||||
def log_exception(sender, exception, **extra):
|
This example shows how to do some extra logging if a theoretical
|
||||||
sender.logger.debug('Got exception during processing: %s', exception)
|
``SecurityException`` was raised:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
from flask import got_request_exception
|
from flask import got_request_exception
|
||||||
got_request_exception.connect(log_exception, app)
|
|
||||||
|
def log_security_exception(sender, exception, **extra):
|
||||||
|
if not isinstance(exception, SecurityException):
|
||||||
|
return
|
||||||
|
|
||||||
|
security_logger.exception(
|
||||||
|
f"SecurityException at {request.url!r}",
|
||||||
|
exc_info=exception,
|
||||||
|
)
|
||||||
|
|
||||||
|
got_request_exception.connect(log_security_exception, app)
|
||||||
|
|
||||||
.. data:: request_tearing_down
|
.. data:: request_tearing_down
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue