Files
portfolio-hub/app/core/errors.py
T

22 lines
707 B
Python

"""Exception types and FastAPI handlers."""
from fastapi import FastAPI, Request, status
from fastapi.responses import JSONResponse
class PortfolioHubError(Exception):
"""Base application exception."""
class FeatureNotReadyError(PortfolioHubError):
"""Raised when an endpoint contract exists but the implementation is pending."""
def register_exception_handlers(app: FastAPI) -> None:
@app.exception_handler(FeatureNotReadyError)
async def handle_not_ready(_: Request, exc: FeatureNotReadyError) -> JSONResponse:
return JSONResponse(
status_code=status.HTTP_501_NOT_IMPLEMENTED,
content={"detail": str(exc) or "Feature not implemented yet"},
)