diff --git a/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java b/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java index 2fcc269..0c53fd0 100644 --- a/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java +++ b/ssw-common/ssw-common-biz/src/main/java/ssw/common/util/SswLLMClient.java @@ -60,6 +60,7 @@ public class SswLLMClient { * @param systemPrompt 系统提示词 (如 jnpf 的 GEN_MODEL_QUETION) * @param userPrompt 用户提示词 (如 "--ai" 描述) * @return LLM 原始输出 (content 字段) + * @throws RuntimeException v0.19+ (BS-新71): AI 配置缺失/异常时显式抛错, 透传到底 */ public String chat(String systemPrompt, String userPrompt) { Map aiConfig = loadDefaultAIConfig(); @@ -68,9 +69,12 @@ public class SswLLMClient { String model = (String) aiConfig.get("model"); if (baseUrl == null || credential == null || model == null) { - log.error("[SswLLMClient] AI 配置缺失 baseUrl={}, credential={}, model={}", + String err = String.format( + "AI 配置缺失 (baseUrl=%s, credential=%s, model=%s). " + + "请检查 base_ai 表 (主库 dbLinkId=0) 是否有 f_enabled_mark=1 记录", baseUrl, credential, model); - return null; + log.error("[SswLLMClient] {}", err); + throw new RuntimeException(err); } JSONObject body = new JSONObject(); @@ -121,15 +125,19 @@ public class SswLLMClient { HttpResponse resp = req.body(requestBody).timeout(READ_TIMEOUT * 1000).execute(); if (!resp.isOk()) { - log.error("[SswLLMClient] HTTP {} body={}", resp.getStatus(), resp.body()); - return null; + // v0.19+ BS-新71: HTTP 失败显式错误 (含 status + body) + String errMsg = String.format("LLM API HTTP %d: %s", resp.getStatus(), + resp.body() != null ? resp.body().substring(0, Math.min(200, resp.body().length())) : ""); + log.error("[SswLLMClient] {}", errMsg); + throw new RuntimeException(errMsg); } JSONObject respJson = JSON.parseObject(resp.body()); if (respJson.containsKey("error") || respJson.containsKey("type") && "error".equals(respJson.getString("type"))) { - log.error("[SswLLMClient] LLM error: {}", respJson.getString("error") != null + String errMsg = "LLM 响应 error: " + (respJson.getString("error") != null ? respJson.getString("error") : respJson.getString("message")); - return null; + log.error("[SswLLMClient] {}", errMsg); + throw new RuntimeException(errMsg); } // 协议差异解析: OpenAI choices[0].message.content vs Anthropic content[0].text @@ -139,8 +147,7 @@ public class SswLLMClient { if (contentArr != null && !contentArr.isEmpty()) { content = contentArr.getJSONObject(0).getString("text"); } else { - log.error("[SswLLMClient] Anthropic 响应无 content: {}", respJson.toJSONString()); - return null; + throw new RuntimeException("Anthropic 响应无 content: " + respJson.toJSONString()); } JSONObject usage = respJson.getJSONObject("usage"); if (usage != null) { @@ -162,9 +169,14 @@ public class SswLLMClient { } return content; + } catch (RuntimeException re) { + // v0.19+ BS-新71: 透传, 不吞 + throw re; } catch (Exception e) { - log.error("[SswLLMClient] 调用异常: {}", e.getMessage(), e); - return null; + // v0.19+ BS-新71: 包装网络异常显式错误 + String errMsg = "SswLLMClient 调用异常: " + e.getMessage(); + log.error(errMsg, e); + throw new RuntimeException(errMsg, e); } }