31 lines
825 B
Python
31 lines
825 B
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
from typing import Any, Dict, Optional
|
|
|
|
|
|
class ErrorCode(str, Enum):
|
|
INVALID_WORKFLOW_TYPE = "INVALID_WORKFLOW_TYPE"
|
|
SQL_GENERATION_FAILED = "SQL_GENERATION_FAILED"
|
|
TABLE_MATCH_FAILED = "TABLE_MATCH_FAILED"
|
|
SQL_EXECUTION_FAILED = "SQL_EXECUTION_FAILED"
|
|
RAGFLOW_RETRIEVE_FAILED = "RAGFLOW_RETRIEVE_FAILED"
|
|
CONFIG_INVALID = "CONFIG_INVALID"
|
|
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
|
|
|
|
@dataclass
|
|
class AppError(Exception):
|
|
code: ErrorCode
|
|
message: str
|
|
status_code: int = 500
|
|
detail: Optional[Dict[str, Any]] = None
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return {
|
|
"code": self.code.value,
|
|
"message": self.message,
|
|
"detail": self.detail or {},
|
|
}
|