fix: handle httpx.RemoteProtocolError during LLM streaming (#8206)
This commit is contained in:
committed by
Caren Thomas
parent
abb325f32d
commit
76008c61f4
@@ -3,6 +3,7 @@ import json
|
||||
import uuid
|
||||
from typing import AsyncIterator, List, Optional
|
||||
|
||||
import httpx
|
||||
from google.genai import Client, errors
|
||||
from google.genai.types import (
|
||||
FunctionCallingConfig,
|
||||
@@ -860,6 +861,17 @@ class GoogleVertexClient(LLMClientBase):
|
||||
},
|
||||
)
|
||||
|
||||
# Handle httpx.RemoteProtocolError which can occur during streaming
|
||||
# when the remote server closes the connection unexpectedly
|
||||
# (e.g., "peer closed connection without sending complete message body")
|
||||
if isinstance(e, httpx.RemoteProtocolError):
|
||||
logger.warning(f"{self._provider_prefix()} Remote protocol error during streaming: {e}")
|
||||
return LLMConnectionError(
|
||||
message=f"Connection error during {self._provider_name()} streaming: {str(e)}",
|
||||
code=ErrorCode.INTERNAL_SERVER_ERROR,
|
||||
details={"cause": str(e.__cause__) if e.__cause__ else None},
|
||||
)
|
||||
|
||||
# Handle connection-related errors
|
||||
if "connection" in str(e).lower() or "timeout" in str(e).lower():
|
||||
logger.warning(f"{self._provider_prefix()} Connection/timeout error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user