public static String buildErrorMessage(final Throwable throwable) {
    if (throwable == null) {
      return "";
    }

    final List<String> messages = dedup(getErrorMessages(throwable));

    final String msg = messages.remove(0);

    final String causeMsg = messages.stream()
        .filter(s -> !s.isEmpty())
        .map(cause -> WordUtils.wrap(PREFIX + cause, 80, "\n\t", true))
        .collect(Collectors.joining(System.lineSeparator()));

    return causeMsg.isEmpty() ? msg : msg + System.lineSeparator() + causeMsg;
  }
@Test
  public void shouldDeduplicateMessage() {
    final Throwable cause = new TestException("Something went wrong");
    final Throwable subLevel3 = new TestException("Something went wrong", cause);
    final Throwable subLevel2 = new TestException("Msg that matches", subLevel3);
    final Throwable subLevel1 = new TestException("Msg that matches", subLevel2);
    final Throwable e = new TestException("Msg that matches", subLevel1);

    assertThat(
        buildErrorMessage(e),
        is("Msg that matches" + System.lineSeparator()
           + "Caused by: Something went wrong")
    );
  }