feat: AI Worker 平台 MVP v1.0.0 - 多租户/项目管理/AI Worker/任务编排/HITL审核/成本治理

This commit is contained in:
2026-08-12 13:30:37 +08:00
parent 6e16ecedec
commit 1b9d09b025
+52
View File
@@ -0,0 +1,52 @@
"""Custom application exceptions."""
from fastapi import HTTPException, status
class AppException(HTTPException):
"""Base application exception."""
def __init__(
self,
detail: str,
status_code: int = status.HTTP_400_BAD_REQUEST,
):
super().__init__(status_code=status_code, detail=detail)
class NotFoundError(AppException):
def __init__(self, resource: str, resource_id=None):
msg = f"{resource} not found"
if resource_id is not None:
msg = f"{resource} #{resource_id} not found"
super().__init__(msg, status.HTTP_404_NOT_FOUND)
class PermissionDeniedError(AppException):
def __init__(self, detail: str = "Permission denied"):
super().__init__(detail, status.HTTP_403_FORBIDDEN)
class TenantMismatchError(AppException):
def __init__(self):
super().__init__(
"Tenant mismatch: resource does not belong to your tenant",
status.HTTP_403_FORBIDDEN,
)
class WorkerOfflineError(AppException):
def __init__(self, worker_name: str):
super().__init__(
f"AI Worker '{worker_name}' is offline or misconfigured",
status.HTTP_503_SERVICE_UNAVAILABLE,
)
class BudgetExceededError(AppException):
def __init__(self, detail: str = "Budget limit exceeded"):
super().__init__(detail, status.HTTP_402_PAYMENT_REQUIRED)
class TaskNotExecutableError(AppException):
def __init__(self, detail: str = "Task cannot be executed in current state"):
super().__init__(detail, status.HTTP_409_CONFLICT)