public static boolean containsMessage(@Nullable Throwable exception, String message) {
    if (exception == null) {
      return false;
    }

    if (exception.getMessage() != null && exception.getMessage().contains(message)) {
      return true;
    }

    return containsMessage(exception.getCause(), message);
  }
@Test
  public void testContainsPositive() {
    assertThat(
            containsMessage(
                new IllegalStateException("RESOURCE_EXHAUSTED: Quota issues"),
                "RESOURCE_EXHAUSTED"))
        .isTrue();
  }