Skip to content

Commit 3c3a471

Browse files
authored
cf: resolve remaining exclude/include slugs after first UnknownModException (#700)
1 parent 418f8f3 commit 3c3a471

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,14 @@ private Mono<Set<Integer>> resolveFromSlugOrIds(
715715
return Mono.just(id);
716716
} catch (NumberFormatException e) {
717717
return context.cfApi.searchMod(s, modsClassId)
718-
.map(CurseForgeMod::getId);
718+
.map(CurseForgeMod::getId)
719+
.doOnError(UnknownModException.class, ex -> {
720+
log.warn("Unable to resolve {} for exclude/include", ex.getSlug(), ex);
721+
})
722+
.onErrorComplete(UnknownModException.class);
719723
}
720724
})
721725
.checkpoint()
722-
.doOnError(UnknownModException.class, e -> {
723-
log.warn("Unable to resolve {} for exclude/include", e.getSlug(), e);
724-
})
725-
.onErrorComplete(UnknownModException.class)
726726
.collect(Collectors.toSet());
727727
}
728728

src/test/java/me/itzg/helpers/curseforge/CurseForgeApiClientTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
77
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
88
import java.util.Collections;
9+
import java.util.Set;
10+
import java.util.stream.Collectors;
911
import me.itzg.helpers.cache.ApiCachingDisabled;
12+
import me.itzg.helpers.curseforge.model.CurseForgeMod;
1013
import me.itzg.helpers.http.SharedFetch.Options;
1114
import org.intellij.lang.annotations.Language;
1215
import org.junit.jupiter.api.Test;
16+
import reactor.core.publisher.Flux;
1317

1418
@WireMockTest
1519
class CurseForgeApiClientTest {
@@ -38,4 +42,30 @@ void apiKeyHeaderIsTrimmed(WireMockRuntimeInfo wmInfo) {
3842
.withHeader("x-api-key", equalTo("key"))
3943
);
4044
}
45+
46+
@Test
47+
void unknownModDoesNotPreventResolvingOthers(WireMockRuntimeInfo wmInfo) {
48+
stubFor(get(urlPathEqualTo("/v1/mods/search"))
49+
.withQueryParam("slug", equalTo("unknown-mod"))
50+
.willReturn(jsonResponse("{\"data\": []}", 200))
51+
);
52+
stubFor(get(urlPathEqualTo("/v1/mods/search"))
53+
.withQueryParam("slug", equalTo("known-mod"))
54+
.willReturn(jsonResponse("{\"data\": [{\"id\": 100, \"classId\": 6, \"gameId\": 432}]}", 200))
55+
);
56+
57+
try (CurseForgeApiClient client = new CurseForgeApiClient(wmInfo.getHttpBaseUrl(),
58+
"key", Options.builder().build(), "432", new ApiCachingDisabled()
59+
)) {
60+
final Set<Integer> ids = Flux.just("unknown-mod", "known-mod")
61+
.flatMap(slug -> client.searchMod(slug, 6)
62+
.map(CurseForgeMod::getId)
63+
.onErrorComplete(UnknownModException.class)
64+
)
65+
.collect(Collectors.toSet())
66+
.block();
67+
68+
assertThat(ids).containsExactly(100);
69+
}
70+
}
4171
}

0 commit comments

Comments
 (0)