from fastapi import Request
from fastapi.responses import JSONResponse
from starlette import status as http_status


class CommercialFeatureError(Exception):
    """社区版暂不支持的商业功能，HTTP 403 + 61xx 业务码。"""

    def __init__(self, code: int = 6101, message: str = "该站点暂不支持此功能") -> None:
        self.code = code
        self.message = message


async def commercial_feature_exception_handler(
    _request: Request,
    exc: CommercialFeatureError,
) -> JSONResponse:
    return JSONResponse(
        status_code=http_status.HTTP_403_FORBIDDEN,
        content={"code": exc.code, "message": exc.message},
    )
