"""FastAPI application entrypoint.""" from __future__ import annotations from fastapi import FastAPI, Request from fastapi.responses import JSONResponse from .api.routes import router from .core.errors import AppError from .core.logging import configure_logging, get_logger def create_app() -> FastAPI: """Create and configure the FastAPI app.""" configure_logging() app = FastAPI(title="Azure Voice Agent") @app.exception_handler(AppError) async def app_error_handler(_: Request, exc: AppError) -> JSONResponse: log = get_logger(error_code=exc.code) log.warning("handled_app_error", message=exc.message, details=exc.details) return JSONResponse( status_code=400, content={"error": {"code": exc.code, "message": exc.message}}, ) @app.exception_handler(Exception) async def unhandled_error_handler(_: Request, exc: Exception) -> JSONResponse: log = get_logger() log.error("unhandled_error", error=str(exc)) return JSONResponse( status_code=500, content={"error": {"code": "internal_error", "message": "Server error."}}, ) app.include_router(router) return app app = create_app()