Skip to content

Commit 78ec538

Browse files
authored
refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information. (#22)
* refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information. * chore(changes): Update CHANGES.md * chore(apollo-java): Streamlined code
1 parent b6cc06a commit 78ec538

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Release Notes.
55
Apollo Java 2.2.0
66

77
------------------
8-
8+
[refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information.](https://github.com/apolloconfig/apollo-java/pull/22)
99
------------------
1010
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/2?closed=1)

apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ public static String getDetailMessage(Throwable ex) {
5252
counter--;
5353
continue;
5454
}
55-
builder.append(" [Cause: ").append(cause.getMessage());
55+
builder.append(" [Cause: ")
56+
.append(cause.getClass().getSimpleName())
57+
.append("(")
58+
.append(cause.getMessage())
59+
.append(")");
5660
}
5761

5862
builder.append(Strings.repeat("]", counter));
5963

6064
return builder.toString();
6165
}
66+
6267
}

apollo-client/src/test/java/com/ctrip/framework/apollo/util/ExceptionUtilTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public void testGetDetailMessageWithCauses() throws Exception {
3838
String causeMsg2 = "another cause";
3939
String someMessage = "some message";
4040

41-
Throwable cause2 = new Throwable(causeMsg2);
41+
Throwable cause2 = new Exception(causeMsg2);
4242
Throwable cause1 = new Throwable(causeMsg1, cause2);
4343
Throwable ex = new Throwable(someMessage, cause1);
4444

45-
String expected = someMessage + " [Cause: " + causeMsg1 + " [Cause: " + causeMsg2 + "]]";
45+
String expected = someMessage + " [Cause: Throwable("+ causeMsg1 +") [Cause: Exception(" + causeMsg2 + ")]]";
4646
assertEquals(expected, ExceptionUtil.getDetailMessage(ex));
4747
}
4848

0 commit comments

Comments
 (0)