From ea6ad1d5b20c77d0f6b1699795053bac60a3c73a Mon Sep 17 00:00:00 2001 From: benya Date: Sun, 8 Feb 2026 02:34:06 +0300 Subject: [PATCH] Improve NPMplus HTTP error details --- services/npmplus.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/npmplus.py b/services/npmplus.py index a6b80e0..fc94d98 100644 --- a/services/npmplus.py +++ b/services/npmplus.py @@ -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