fix: distinguish Gemini timeout
This commit is contained in:
@@ -179,6 +179,12 @@ async def ask_knowledge_chat(payload: ChatRequest, _session=Depends(verify_sessi
|
||||
429: "Gemini API 사용 한도에 도달했습니다. 잠시 후 다시 시도해 주세요.",
|
||||
}.get(exc.response.status_code, "Gemini 요청에 실패했습니다. 잠시 후 다시 시도해 주세요.")
|
||||
raise HTTPException(status_code=502, detail=detail) from exc
|
||||
except httpx.TimeoutException as exc:
|
||||
raise HTTPException(
|
||||
status_code=504,
|
||||
detail="Gemini 3.8 Flash 응답이 지연되어 시간 초과됐습니다. "
|
||||
"잠시 후 다시 시도해 주세요.",
|
||||
) from exc
|
||||
except (httpx.RequestError, ValueError) as exc:
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
@@ -65,6 +66,30 @@ def test_busy_gemini_is_retried_and_reported(monkeypatch):
|
||||
assert "요청이 몰려" in error.value.detail
|
||||
|
||||
|
||||
def test_gemini_timeout_is_reported(monkeypatch):
|
||||
monkeypatch.setenv("GEMINI_API_KEY", "test-key")
|
||||
monkeypatch.setattr(chat, "search", lambda _question: [])
|
||||
|
||||
class Client:
|
||||
def __init__(self, timeout):
|
||||
pass
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_args):
|
||||
pass
|
||||
|
||||
async def post(self, *_args, **_kwargs):
|
||||
raise httpx.ReadTimeout("timed out")
|
||||
|
||||
monkeypatch.setattr(chat.httpx, "AsyncClient", Client)
|
||||
with pytest.raises(HTTPException) as error:
|
||||
asyncio.run(chat.ask_knowledge_chat(chat.ChatRequest(question="일위대가가 뭐야"), {}))
|
||||
assert error.value.status_code == 504
|
||||
assert "시간 초과" in error.value.detail
|
||||
|
||||
|
||||
def test_chat_searches_all_knowledge_markdown_except_excluded_folders(monkeypatch, tmp_path):
|
||||
public = tmp_path / "original" / "법률"
|
||||
guide = tmp_path / "technical_info"
|
||||
|
||||
Reference in New Issue
Block a user