""" 自定义业务异常类 用于区分业务逻辑错误和系统错误 """ from .response_code import ResponseCode, ResponseMessage class BusinessException(Exception): """业务异常基类""" def __init__(self, message: str, code: int = None): self.message = message self.code = code or ResponseCode.INTERNAL_ERROR super().__init__(self.message) class DataNotFoundException(BusinessException): """数据不存在异常""" def __init__(self, message: str = None): super().__init__( message or ResponseMessage.DATA_NOT_FOUND, ResponseCode.DATA_NOT_FOUND ) class AccountNotFoundException(BusinessException): """账号不存在异常""" def __init__(self, message: str = None): super().__init__( message or ResponseMessage.ACCOUNT_NOT_FOUND, ResponseCode.ACCOUNT_NOT_FOUND ) class DataExistsException(BusinessException): """数据已存在异常""" def __init__(self, message: str = None): super().__init__( message or ResponseMessage.DATA_EXISTS, ResponseCode.DATA_EXISTS ) class ValidationException(BusinessException): """数据验证异常""" def __init__(self, message: str = None): super().__init__( message or ResponseMessage.BAD_REQUEST, ResponseCode.VALIDATION_ERROR ) class ExportException(BusinessException): """导出异常""" def __init__(self, message: str = None): super().__init__( message or ResponseMessage.EXPORT_FAILED, ResponseCode.EXPORT_FAILED )