refactor(basic): 优化 N9E 信息获取逻辑

- 使用 try-with-resources 确保 HttpResponse 资源正确关闭- 添加异常捕获,当请求失败时记录日志并终止方法执行
This commit is contained in:
2025-09-10 16:15:51 +08:00
parent 7839082352
commit 0c56a7fa67

View File

@@ -42,12 +42,17 @@ public class N9eSyncTask {
requestBody.put("queries", queries); requestBody.put("queries", queries);
// 发送POST请求 // 发送POST请求
HttpResponse response = HttpUtil.createPost("https://n9e.jerryyan.top/v1/n9e/target/list") Map<String, Object> respData;
try (HttpResponse response = HttpUtil.createPost("https://n9e.jerryyan.top/v1/n9e/target/list")
.header("Authorization", auth) .header("Authorization", auth)
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.body(JacksonUtil.toJSONString(requestBody)) .body(JacksonUtil.toJSONString(requestBody))
.execute(); .execute()) {
Map<String, Object> respData = JacksonUtil.parseObject(response.body(), Map.class); respData = JacksonUtil.parseObject(response.body(), Map.class);
} catch (Exception e) {
log.warn("N9E信息获取失败");
return;
}
String err = (String) respData.get("err"); String err = (String) respData.get("err");
if (StringUtils.isNotBlank(err)) { if (StringUtils.isNotBlank(err)) {
log.warn("N9E信息获取失败"); log.warn("N9E信息获取失败");