fix: tolerate gateways without image profiles
This commit is contained in:
@@ -16,6 +16,7 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import tomllib
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
@@ -23,7 +24,7 @@ from typing import Any
|
||||
|
||||
|
||||
APP_NAME = "codex-retry-gateway-tui"
|
||||
FALLBACK_VERSION = "0.1.8"
|
||||
FALLBACK_VERSION = "0.1.9"
|
||||
DEFAULT_GATEWAY_ADMIN_PATH = "/__codex_retry_gateway"
|
||||
DEFAULT_GATEWAY_URL = "http://127.0.0.1:4610/__codex_retry_gateway"
|
||||
DEFAULT_API_URL = DEFAULT_GATEWAY_URL
|
||||
@@ -1150,11 +1151,21 @@ def fetch_payload(api_url: str, timeout: int, access_key: str = "") -> dict[str,
|
||||
return data
|
||||
|
||||
|
||||
def fetch_optional_payload(url: str, timeout: int, access_key: str = "") -> tuple[dict[str, Any], str]:
|
||||
def fetch_optional_payload(
|
||||
url: str,
|
||||
timeout: int,
|
||||
access_key: str = "",
|
||||
*,
|
||||
allow_not_found: bool = False,
|
||||
) -> tuple[dict[str, Any], str]:
|
||||
if not str(url or "").strip():
|
||||
return {}, ""
|
||||
try:
|
||||
return fetch_payload(url, timeout, access_key), ""
|
||||
except urllib.error.HTTPError as exc:
|
||||
if allow_not_found and exc.code == 404:
|
||||
return {}, ""
|
||||
return {}, str(exc)
|
||||
except Exception as exc:
|
||||
return {}, str(exc)
|
||||
|
||||
@@ -2030,12 +2041,12 @@ def fetch_dashboard_snapshot(
|
||||
"image_profiles": build_api_url(gateway_root, "/api/image-profiles"),
|
||||
}
|
||||
|
||||
def fetch_optional(url: str) -> tuple[dict[str, Any], str]:
|
||||
return fetch_optional_payload(url, timeout, access_key)
|
||||
def fetch_optional(url: str, *, allow_not_found: bool = False) -> tuple[dict[str, Any], str]:
|
||||
return fetch_optional_payload(url, timeout, access_key, allow_not_found=allow_not_found)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=5) as pool:
|
||||
futures = {
|
||||
name: pool.submit(fetch_optional, url)
|
||||
name: pool.submit(fetch_optional, url, allow_not_found=name == "image_profiles")
|
||||
for name, url in endpoints.items()
|
||||
}
|
||||
status_payload, status_error = futures["status"].result()
|
||||
|
||||
Reference in New Issue
Block a user