mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🐛 fix(http_utils): 改进HTTP错误处理,记录请求失败的状态码和响应内容
This commit is contained in:
parent
249c8fe3ed
commit
4995c8b19a
@ -262,13 +262,19 @@ class AsyncHttpx:
|
|||||||
"AsyncHttpx:FallbackExecutor",
|
"AsyncHttpx:FallbackExecutor",
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
except HTTPStatusError as e:
|
except Exception as e:
|
||||||
exceptions.append(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(
|
logger.debug(
|
||||||
f"请求失败: {url} {e.response.status_code} {e.response.text}",
|
f"请求失败: {url} {status} {body_text}",
|
||||||
"AsyncHttpx:FallbackExecutor",
|
"AsyncHttpx:FallbackExecutor",
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
exceptions.append(e)
|
exceptions.append(e)
|
||||||
if url != url_list[-1]:
|
if url != url_list[-1]:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user