INNER CODE UNIT · Python

custom_error_handler

stacklok/codegate · src/codegate/server.py:28

async def custom_error_handler(request, exc: Exception):
    """This is a Middleware to handle exceptions and log them."""
    # Capture the stack trace
    extracted_traceback = traceback.extract_tb(exc.__traceback__)
    # Log only the last 3 items of the stack trace. 3 is an arbitrary number.
    logger.error(traceback.print_list(extracted_traceback[-3:]), exc_info=exc)
    return JSONResponse({"error": str(exc)}, status_code=500)


class CodeGateServer(FastAPI):
    provider_registry: ProviderRegistry = None

    def set_provider_registry(self, registry: ProviderRegistry):
        self.provider_registry = registry


def init_app(pipeline_factory: PipelineFactory) -> CodeGateServer:
    """Create the FastAPI application."""

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…