INNER CODE UNIT · Python

api_exception_handler

akutayural/APIException · api_exception/__init__.py:339

    async def api_exception_handler(request: Request, exc: APIException):
        # Central place to log raised APIException
        if log and getattr(exc, "log_exception", True) is True:
            meta: Dict[str, Any] = {
                "event": "api_exception",
                "path": request.url.path,
                "method": request.method,
                "client_ip": request.client.host if request.client else "unknown",
                "http_version": request.scope.get("http_version", None),
                "error_code": getattr(exc, "error_code", None),
                "status": getattr(exc.status, "value", str(getattr(exc, "status", ""))),
                "http_status": getattr(exc, "http_status_code", None),
            }

            if log_request_context:
                meta.update(_collect_headers(request, log_header_keys))

                # Users can pass any dict/str here; we attach it as structured extra

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…