From 46dbb32064a782db9ed9f49d7c6a2f1a9ee0d694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=B8=E7=86=9F=E5=90=B4=E5=BD=A6=E7=A5=96?= Date: Wed, 21 Jan 2026 17:38:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(http):=20=E4=BC=98=E5=8C=96HTTP=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除超时异常中的线程中断操作,避免影响主线程状态 - 分离IOException和InterruptedException的处理逻辑 - 为不同异常类型提供更精确的错误信息 - 恢复被中断线程的状态标记 - 移除过时的代码注释块 --- .../java/com/gaotao/common/utils/HttpUtils.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gaotao/common/utils/HttpUtils.java b/src/main/java/com/gaotao/common/utils/HttpUtils.java index 39bf246..17af441 100644 --- a/src/main/java/com/gaotao/common/utils/HttpUtils.java +++ b/src/main/java/com/gaotao/common/utils/HttpUtils.java @@ -99,13 +99,19 @@ public class HttpUtils { HttpResponse response = client.send(builder.build(), HttpResponse.BodyHandlers.ofString()); return handleResponse(response); } catch (java.net.http.HttpTimeoutException e) { - // 超时异常特殊处理 - rqrq - Thread.currentThread().interrupt(); throw new RuntimeException("接口响应超时(60秒),请检查网络连接或者接口服务是否可用。 " ); - } catch (IOException | InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException("POST 请求失败: " + e.getMessage(), e); + } catch (IOException e) { + // IO 错误:不涉及中断 + throw new RuntimeException("网络或IO错误: " + e.getMessage(), e); + } catch (InterruptedException e) { + // 线程被中断:恢复中断状态,并抛出异常(或返回) + Thread.currentThread().interrupt(); // ✅ 合理 + throw new RuntimeException("请求被中断", e); } + // (IOException | InterruptedException e) { + // Thread.currentThread().interrupt(); + // throw new RuntimeException("POST 请求失败: " + e.getMessage(), e); + // } } /** 构建查询参数字符串 */