Improve NPMplus HTTP error details

This commit is contained in:
2026-02-08 02:34:06 +03:00
parent e1b0f1153e
commit ea6ad1d5b2

View File

@@ -48,7 +48,17 @@ def _request_json(
with urlopen(req, timeout=10, context=context) as resp:
payload = resp.read().decode("utf-8")
except HTTPError as e:
raise RuntimeError(f"HTTP {e.code}") from e
detail = f"HTTP {e.code}"
try:
payload = e.read().decode("utf-8").strip()
except Exception:
payload = ""
if payload:
payload = " ".join(payload.split())
if len(payload) > 300:
payload = payload[:300] + "..."
detail = f"{detail}: {payload}"
raise RuntimeError(f"{detail} ({url})") from e
except URLError as e:
raise RuntimeError(str(e.reason)) from e