fix: let transport errors propagate raw from legacy cloud methods, matching 0.2.x

0.2.8 had no try/except around its requests calls: ConnectionError/Timeout
reached the caller as-is, and is_retrieval_ready — which only catches
PageIndexAPIError — deliberately let them escape its polling loop. Wrapping
every RequestException into PageIndexAPIError (introduced alongside the
timeout in 595895c, unmentioned in its message) turned a network outage into
a silent not-ready that polls until timeout. Keep the timeout; drop the
wrapping, including the two per-stream re-wraps.
This commit is contained in:
Ray 2026-07-22 12:27:15 +08:00
parent d1824e4d6e
commit fdd075b92d

View file

@ -44,15 +44,14 @@ class LegacyCloudAPI:
# forever. Streamed responses get a longer read timeout since it
# applies between chunks, not to the whole response.
kwargs.setdefault("timeout", 120 if kwargs.get("stream") else 30)
try:
response = requests.request(
method,
f"{self.base_url}{path}",
headers=self._headers(),
**kwargs,
)
except requests.RequestException as e:
raise PageIndexAPIError(f"{error_prefix}: {e}") from e
# Transport errors propagate raw (0.2.x contract) — they must escape
# is_retrieval_ready's except-PageIndexAPIError, not read as "not ready".
response = requests.request(
method,
f"{self.base_url}{path}",
headers=self._headers(),
**kwargs,
)
if response.status_code != 200:
msg = f"{error_prefix}: {response.text}"
@ -209,8 +208,6 @@ class LegacyCloudAPI:
content = choices[0].get("delta", {}).get("content", "")
if content:
yield content
except requests.RequestException as e:
raise PageIndexAPIError(f"Failed to stream chat completion: {e}") from e
finally:
response.close()
@ -230,8 +227,6 @@ class LegacyCloudAPI:
yield json.loads(data)
except json.JSONDecodeError:
continue
except requests.RequestException as e:
raise PageIndexAPIError(f"Failed to stream chat completion: {e}") from e
finally:
response.close()