🐛 fix(http_utils): 改进HTTP错误处理,记录请求失败的状态码和响应内容

This commit is contained in:
HibiKier 2025-10-16 17:28:09 +08:00
parent 249c8fe3ed
commit 4995c8b19a

View File

@ -262,13 +262,19 @@ class AsyncHttpx:
"AsyncHttpx:FallbackExecutor",
)
return result
except HTTPStatusError as e:
exceptions.append(e)
logger.debug(
f"请求失败: {url} {e.response.status_code} {e.response.text}",
"AsyncHttpx:FallbackExecutor",
)
except Exception as e:
if isinstance(e, HTTPStatusError):
status = getattr(e.response, "status_code", "?")
try:
body_text = getattr(e.response, "text", None)
if body_text is not None and len(body_text) > 2000:
body_text = body_text[:2000] + "...(truncated)"
except Exception:
body_text = "<unavailable>"
logger.debug(
f"请求失败: {url} {status} {body_text}",
"AsyncHttpx:FallbackExecutor",
)
exceptions.append(e)
if url != url_list[-1]:
logger.warning(