Private
Public Access
refactor(ai_client): classifier functions return ErrorInfo instead of ProviderError
The 6 error-classifier functions in ai_client.py, openai_compatible.py, and qwen_adapter.py now return ErrorInfo (data-oriented) instead of ProviderError. Each takes a source: str parameter for telemetry provenance. ProviderError class is still used in production code paths (Task 3.4) and will be removed in Task 3.7.
This commit is contained in:
+12
-11
@@ -4,6 +4,8 @@ from typing import Any, Callable, Optional
|
||||
|
||||
from openai import OpenAIError, RateLimitError, AuthenticationError, PermissionDeniedError, APIConnectionError, APIStatusError, BadRequestError
|
||||
|
||||
from src.result_types import ErrorInfo, ErrorKind
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class NormalizedResponse:
|
||||
text: str
|
||||
@@ -36,27 +38,26 @@ def _to_dict_tool_call(tc: Any) -> dict[str, Any]:
|
||||
},
|
||||
}
|
||||
|
||||
def _classify_openai_compatible_error(exc: Exception) -> "ProviderError":
|
||||
from src.ai_client import ProviderError
|
||||
def _classify_openai_compatible_error(exc: Exception, source: str = "openai_compatible") -> ErrorInfo:
|
||||
if isinstance(exc, RateLimitError):
|
||||
return ProviderError(kind="rate_limit", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.RATE_LIMIT, message=str(exc), source=source, original=exc)
|
||||
if isinstance(exc, AuthenticationError) or isinstance(exc, PermissionDeniedError):
|
||||
return ProviderError(kind="auth", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.AUTH, message=str(exc), source=source, original=exc)
|
||||
if isinstance(exc, APIConnectionError):
|
||||
return ProviderError(kind="network", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.NETWORK, message=str(exc), source=source, original=exc)
|
||||
if isinstance(exc, APIStatusError):
|
||||
code = getattr(exc, "status_code", 0)
|
||||
if code == 402:
|
||||
return ProviderError(kind="balance", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.BALANCE, message=str(exc), source=source, original=exc)
|
||||
if code == 429:
|
||||
return ProviderError(kind="rate_limit", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.RATE_LIMIT, message=str(exc), source=source, original=exc)
|
||||
if code in (401, 403):
|
||||
return ProviderError(kind="auth", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.AUTH, message=str(exc), source=source, original=exc)
|
||||
if code in (500, 502, 503, 504):
|
||||
return ProviderError(kind="network", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.NETWORK, message=str(exc), source=source, original=exc)
|
||||
if isinstance(exc, BadRequestError):
|
||||
return ProviderError(kind="quota", provider="openai_compatible", original=exc)
|
||||
return ProviderError(kind="unknown", provider="openai_compatible", original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.QUOTA, message=str(exc), source=source, original=exc)
|
||||
return ErrorInfo(kind=ErrorKind.UNKNOWN, message=str(exc), source=source, original=exc)
|
||||
|
||||
def send_openai_compatible(
|
||||
client: Any,
|
||||
|
||||
Reference in New Issue
Block a user