Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion airflow/api_fastapi/execution_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
from typing import TYPE_CHECKING

import attrs
from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse

if TYPE_CHECKING:
import httpx

import structlog

logger = structlog.get_logger(logger_name=__name__)


@asynccontextmanager
async def lifespan(app: FastAPI):
Expand Down Expand Up @@ -86,6 +91,16 @@ def custom_openapi() -> dict:
app.openapi = custom_openapi # type: ignore[method-assign]

app.include_router(execution_api_router)

# As we are mounted as a sub app, we don't get any logs for unhandled exceptions without this!
@app.exception_handler(Exception)
def handle_exceptions(request: Request, exc: Exception):
logger.exception("Handle died with an error", exc_info=(type(exc), exc, exc.__traceback__))
content = {"message": "Internal server error"}
if "correlation-id" in request.headers:
content["correlation-id"] = request.headers["correlation-id"]
return JSONResponse(status_code=500, content=content)

return app


Expand Down
Loading