main.py 739 B

123456789101112131415161718192021
  1. from __future__ import annotations
  2. from fastapi import FastAPI
  3. from fastapi.responses import JSONResponse
  4. from starlette.requests import Request
  5. from bom_assistant.api.routes import router
  6. from bom_assistant.scouting.errors import RowNotFoundError, SessionNotFoundError
  7. app = FastAPI(title="Instant BOM Assistant")
  8. app.include_router(router)
  9. @app.exception_handler(SessionNotFoundError)
  10. def _session_not_found(request: Request, exc: SessionNotFoundError) -> JSONResponse:
  11. return JSONResponse(status_code=404, content={"detail": str(exc)})
  12. @app.exception_handler(RowNotFoundError)
  13. def _row_not_found(request: Request, exc: RowNotFoundError) -> JSONResponse:
  14. return JSONResponse(status_code=404, content={"detail": str(exc)})