from fastapi import Request, HTTPException
from fastapi.responses import JSONResponse

from apis.base import standard_error_response


class BizException(HTTPException):
    def __init__(self, message: str = "请求异常", status_code: int = 500):
        super().__init__(status_code=status_code, detail=message)


class BizExceptionHandlers:
    @staticmethod
    async def biz_exception_handler(request: Request, exc: HTTPException):
        return JSONResponse(
            content=standard_error_response(code=exc.status_code, message=exc.detail).dict(),
            status_code=exc.status_code
        )

