lavkach3
14 строк · 566.0 Байт
1from fastapi.exceptions import HTTPException2
3
4class ModuleException(HTTPException):5def __init__(self, status_code: int, enum=None, code: str | None = None, message: str|None = None):6if not enum and (code and message):7raise ModuleException(status_code=500, code='ENUM_ERROR', message='Enum not found')8if enum:9code = enum.name10message = enum.value + message if message else ''11super().__init__(status_code=status_code, detail={12'code': code,13'msg': f' {message}'14})15