Skip to content

Commit

Permalink
[MINDEXER-207] Handle HTTP 404 gracefully (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas authored Oct 30, 2023
1 parent 1343cb5 commit 851856d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public RemoteRepositorySearchResponse search(SearchRequest searchRequest) throws
try (Transport.Response response = transport.get(uri, commonHeaders)) {
if (response.getCode() == 200) {
document = Jsoup.parse(response.getBody(), StandardCharsets.UTF_8.name(), uri, parser);
} else if (response.getCode() == 404) {
document = Jsoup.parse(InputStream.nullInputStream(), StandardCharsets.UTF_8.name(), uri, parser);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ public void smoke() throws IOException {
dumpPage(searchResponse);
}

@Test
public void notFound404Response() throws IOException {
// LIST GAs
SearchRequest searchRequest =
new SearchRequest(FieldQuery.fieldQuery(MAVEN.GROUP_ID, "org.cstamas.no-such-thing"));
RemoteRepositorySearchResponse searchResponse = backend.search(searchRequest);
assertThat(searchResponse.getTotalHits(), equalTo(0));
System.out.println("TOTAL HITS: " + searchResponse.getTotalHits());
}

@Test
public void g() throws IOException {
// LIST GAs
Expand Down

0 comments on commit 851856d

Please sign in to comment.