diff --git a/CHANGES.md b/CHANGES.md index ec72fc2e..5df63b99 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,6 @@ Release Notes. Apollo Java 2.2.0 ------------------ - +[refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information.](https://github.com/apolloconfig/apollo-java/pull/22) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/2?closed=1) \ No newline at end of file diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java index 0a179d97..28df3f5f 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java @@ -52,11 +52,16 @@ public static String getDetailMessage(Throwable ex) { counter--; continue; } - builder.append(" [Cause: ").append(cause.getMessage()); + builder.append(" [Cause: ") + .append(cause.getClass().getSimpleName()) + .append("(") + .append(cause.getMessage()) + .append(")"); } builder.append(Strings.repeat("]", counter)); return builder.toString(); } + } diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/util/ExceptionUtilTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/util/ExceptionUtilTest.java index 1077c41a..e8d3d671 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/util/ExceptionUtilTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/util/ExceptionUtilTest.java @@ -38,11 +38,11 @@ public void testGetDetailMessageWithCauses() throws Exception { String causeMsg2 = "another cause"; String someMessage = "some message"; - Throwable cause2 = new Throwable(causeMsg2); + Throwable cause2 = new Exception(causeMsg2); Throwable cause1 = new Throwable(causeMsg1, cause2); Throwable ex = new Throwable(someMessage, cause1); - String expected = someMessage + " [Cause: " + causeMsg1 + " [Cause: " + causeMsg2 + "]]"; + String expected = someMessage + " [Cause: Throwable("+ causeMsg1 +") [Cause: Exception(" + causeMsg2 + ")]]"; assertEquals(expected, ExceptionUtil.getDetailMessage(ex)); }