mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
🐛 fix(http_utils): 改进HTTP错误处理,记录请求失败的状态码和响应内容
This commit is contained in:
parent
249c8fe3ed
commit
4995c8b19a
@ -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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user