现象:CmsSiteDirectoryImpl 两处 catch 只打 e.getMessage(),而平台 SDK 统一把 传输层失败包成 "OpenAPI request failed: ioError",底层 ConnectException / SocketTimeoutException / SSLException 全部丢失,日志分不清"对端没起"还是"读超时"。 改动: - 新增 rootCauseBrief():沿 cause 链取最内层原因追加为"(根因 X: msg)"; 无 cause 时不追加,避免与 e.getMessage() 重复。 - resolveSite / listSites 两处 catch 日志接入该方法。 契约不变:路径 /oapi/site/list、per-target basePath /cms、fail-closed 语义均未动。 测试:CmsSiteDirectoryImplTest 新增 1 例断言摘要形态;mvn test 82/82 绿。
This commit is contained in:
@@ -123,4 +123,20 @@ class CmsSiteDirectoryImplTest {
|
||||
void listSites_rejectsNullSchId() {
|
||||
assertThrows(BizException.class, () -> directory.listSites(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("rootCauseBrief:ioError 包装层要透出最内层原因(区分\"对端没起\"与\"读超时\")")
|
||||
void rootCauseBrief_exposesInnermostCause() {
|
||||
// 无 cause:不追加,避免与 e.getMessage() 重复
|
||||
assertEquals("", CmsSiteDirectoryImpl.rootCauseBrief(
|
||||
new RuntimeException("OpenAPI request failed: ioError")));
|
||||
|
||||
// 实际形态:OpenApiException(ioError) ← ResourceAccessException ← ConnectException
|
||||
java.net.ConnectException refused = new java.net.ConnectException("Connection refused: connect");
|
||||
Exception wrapped = new RuntimeException("OpenAPI request failed: ioError",
|
||||
new RuntimeException("I/O error on GET request", refused));
|
||||
String brief = CmsSiteDirectoryImpl.rootCauseBrief(wrapped);
|
||||
assertTrue(brief.contains("ConnectException"), brief);
|
||||
assertTrue(brief.contains("Connection refused: connect"), brief);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user