public static boolean containsType(
      @Nullable Throwable exception, Class<? extends Throwable> type) {
    if (exception == null) {
      return false;
    }

    if (type.isAssignableFrom(exception.getClass())) {
      return true;
    }

    return containsType(exception.getCause(), type);
  }
@Test
  public void testContainsTypeNegative() {
    assertThat(
            containsType(
                new IllegalStateException("RESOURCE_EXHAUSTED: Quota issues"),
                IllegalArgumentException.class))
        .isFalse();
  }