.. _error-handler-signals:
Signals from ErrorHandler
=========================
The :py:class:`lback.core.error_handler.ErrorHandler` class is responsible for gracefully handling various application errors and exceptions, generating appropriate HTTP responses. This class emits signals at key moments when error responses are generated, providing **critical hooks for centralized error logging, custom error reporting, and integrating with external monitoring and alerting systems.**
.. list-table::
:widths: 25 50 25
:header-rows: 1
* - Signal Name
- Description
- Arguments (`kwargs`)
* - ``error_handler_initialized``
- Emitted immediately after the :py:class:`~lback.core.error_handler.ErrorHandler` instance has been successfully initialized.
- ``sender`` (:py:class:`~lback.core.error_handler.ErrorHandler`): The instance of the error handler.
* - ``error_response_generated``
- Emitted whenever a standard error response (e.g., 404 Not Found, 403 Forbidden, 500 Internal Server Error from explicit `handle_500`, or custom errors) is generated by the error handler.
- ``sender`` (:py:class:`~lback.core.error_handler.ErrorHandler`): The error handler instance.
``status_code`` (:py:class:`int`): The HTTP status code of the generated error response (e.g., 404, 403, 500).
``error_message`` (:py:class:`str`): A general message describing the error.
``request`` (:py:class:`Any`, *optional*): The incoming request object that led to the error, if available.
``response`` (:py:class:`~lback.core.response.Response`): The generated HTTP response object.
``exception`` (:py:class:`Exception`, *optional*): The exception object if the error originated from an explicit exception (e.g., in `handle_500`).
``allowed_methods`` (:py:class:`list`, *optional*): A list of allowed HTTP methods, specifically for 405 Method Not Allowed errors.
* - ``unhandled_exception_response_generated``
- Emitted specifically when an *unhandled exception* occurs during request processing, leading to a 500 Internal Server Error response. This signal provides detailed context about the exception.
- ``sender`` (:py:class:`~lback.core.error_handler.ErrorHandler`): The error handler instance.
``status_code`` (:py:class:`int`): The HTTP status code (always 500).
``exception`` (:py:class:`Exception`): The unhandled exception object that occurred.
``request`` (:py:class:`Any`): The incoming request object during which the exception occurred.
``response`` (:py:class:`~lback.core.response.Response`): The generated HTTP response object.