46 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import HTTPException, status
class SiliconFlowAPIException(Exception):
"""硅基流动API异常"""
def __init__(self, detail: str, status_code: int = 500):
self.detail = detail
self.status_code = status_code
super().__init__(detail)
def __str__(self):
return f"SiliconFlowAPI Error [{self.status_code}]: {self.detail}"
class AICommandParseException(HTTPException):
def __init__(self, detail: str):
super().__init__(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"AI command parse error: {detail}"
)
class SwitchConfigException(HTTPException):
def __init__(
self,
detail: str,
status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR
):
super().__init__(
status_code=status_code,
detail=f"Switch error: {detail}"
)
class ConfigBackupException(SwitchConfigException):
"""配置备份失败异常"""
def __init__(self, ip: str):
super().__init__(
detail=f"无法备份设备 {ip} 的配置"
)
self.recovery_guide = "检查设备存储空间或权限" # 在子类中存储恢复指南
class ConfigRollbackException(SwitchConfigException):
"""回滚失败异常"""
def __init__(self, ip: str, original_error: str):
super().__init__(
detail=f"设备 {ip} 回滚失败(原始错误:{original_error}",
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY
)
self.recovery_guide = "尝试手动恢复配置或重启设备"