mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-25 05:52:34 +00:00
fix(tools): wrap browser provider network calls with error handling
Wrap requests.post() in create_session() for browser_use, browserbase, and firecrawl providers with requests.RequestException handling. Connection timeouts and DNS resolution failures now surface as clean RuntimeError messages instead of raw requests exception tracebacks. Browser Use managed-gateway mode preserves raw exception propagation so the existing idempotency-key retry semantics keep working. Closes #2746 Co-authored-by: teknium1 <127238744+teknium1@users.noreply.github.com>
This commit is contained in:
parent
6af9942327
commit
13c72fb486
3 changed files with 68 additions and 48 deletions
|
|
@ -137,12 +137,22 @@ class BrowserUseProvider(CloudBrowserProvider):
|
||||||
else {}
|
else {}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{config['base_url']}/browsers",
|
f"{config['base_url']}/browsers",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=payload,
|
json=payload,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
)
|
)
|
||||||
|
except requests.RequestException as exc:
|
||||||
|
# Managed mode: propagate raw so callers can retry with the
|
||||||
|
# preserved idempotency key. Direct mode: wrap network failures
|
||||||
|
# into a clean RuntimeError for end users.
|
||||||
|
if managed_mode:
|
||||||
|
raise
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Browser Use API connection failed: {exc}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
if managed_mode and not _should_preserve_pending_create_key(response):
|
if managed_mode and not _should_preserve_pending_create_key(response):
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ class BrowserbaseProvider(CloudBrowserProvider):
|
||||||
"X-BB-API-Key": config["api_key"],
|
"X-BB-API-Key": config["api_key"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{config['base_url']}/v1/sessions",
|
f"{config['base_url']}/v1/sessions",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
|
@ -131,6 +132,10 @@ class BrowserbaseProvider(CloudBrowserProvider):
|
||||||
json=session_config,
|
json=session_config,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
)
|
)
|
||||||
|
except requests.RequestException as exc:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Browserbase API connection failed: {exc}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,17 @@ class FirecrawlProvider(CloudBrowserProvider):
|
||||||
|
|
||||||
body: Dict[str, object] = {"ttl": ttl}
|
body: Dict[str, object] = {"ttl": ttl}
|
||||||
|
|
||||||
|
try:
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{self._api_url()}/v2/browser",
|
f"{self._api_url()}/v2/browser",
|
||||||
headers=self._headers(),
|
headers=self._headers(),
|
||||||
json=body,
|
json=body,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
)
|
)
|
||||||
|
except requests.RequestException as exc:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Firecrawl API connection failed: {exc}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue