异常日志完善

This commit is contained in:
zhaoqingliang
2025-10-30 18:25:03 +08:00
parent 89af7cd0a4
commit 39911d78ab
10 changed files with 142 additions and 9 deletions

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import logging
from typing import Any, Dict, List, Tuple
import httpx
@ -16,6 +17,9 @@ from app.models import (
from app.providers.base import LLMProviderClient
logger = logging.getLogger(__name__)
class AnthropicProvider(LLMProviderClient):
name = LLMProvider.ANTHROPIC.value
api_key_env = "ANTHROPIC_API_KEY"
@ -52,7 +56,19 @@ class AnthropicProvider(LLMProviderClient):
try:
response = await client.post(self.base_url, json=payload, headers=headers)
response.raise_for_status()
except httpx.HTTPStatusError as exc:
status_code = exc.response.status_code
body = exc.response.text
logger.error(
"Anthropic upstream returned %s: %s", status_code, body, exc_info=True
)
raise ProviderAPICallError(
f"Anthropic request failed with status {status_code}",
status_code=status_code,
response_text=body,
) from exc
except httpx.HTTPError as exc:
logger.error("Anthropic transport error: %s", exc, exc_info=True)
raise ProviderAPICallError(f"Anthropic request failed: {exc}") from exc
data: Dict[str, Any] = response.json()