ushka.core.error_handler
This module provides centralized exception handling for the Ushka framework.
It includes an ErrorHandler class to manage both expected HTTP errors (4xx)
and unexpected server errors (5xx), rendering appropriate error pages.
Additionally, it features a _TracebackInspector utility for safe and
detailed stack trace extraction during debugging.
class ErrorHandler
Manages global exceptions within the application lifecycle.
This handler supports asynchronous rendering and provides detailed context (including the Request object) to error templates.
__init__(self, config: Config, log: logging.Logger, router: Optional[Router] = None) -> None
Initializes the ErrorHandler.
Parameters
config | Config | The application configuration object. |
log | logging.Logger | The logger instance used for recording server errors. |
router | Optional[Router] | The application router, used primarily for listing available routes in debug mode (e.g., on 404 pages). Default is None. |
handle_exception(self, exc: Exception, request: Request) -> Response
Single entry point for error handling.
Delegates handling based on whether the exception is an expected HTTPError or an unexpected server error.
Parameters
exc | Exception | The exception that occurred. |
request | Request | The incoming HTTP request object. |
Returns
Response | The HTTP response object containing the error page content. |