From 1b9d09b025d6a14fa7ad05df377e2f349619af19 Mon Sep 17 00:00:00 2001 From: huangzhuang_3rd Date: Wed, 12 Aug 2026 13:30:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20AI=20Worker=20=E5=B9=B3=E5=8F=B0=20MVP?= =?UTF-8?q?=20v1.0.0=20-=20=E5=A4=9A=E7=A7=9F=E6=88=B7/=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86/AI=20Worker/=E4=BB=BB=E5=8A=A1=E7=BC=96?= =?UTF-8?q?=E6=8E=92/HITL=E5=AE=A1=E6=A0=B8/=E6=88=90=E6=9C=AC=E6=B2=BB?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/core/exceptions.py | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 backend/app/core/exceptions.py diff --git a/backend/app/core/exceptions.py b/backend/app/core/exceptions.py new file mode 100644 index 0000000..e643c6e --- /dev/null +++ b/backend/app/core/exceptions.py @@ -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)