Skip to content

Commit

Permalink
Add http response message (and log some details) (#11341)
Browse files Browse the repository at this point in the history
* Add http response message (and log some details)

* Fix typo

* Update CHANGELOG.md
  • Loading branch information
koppor authored May 27, 2024
1 parent e23d286 commit e1da33d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We replaced the word "Key bindings" with "Keyboard shortcuts" in the Preferences tab. [#11153](https://github.com/JabRef/jabref/pull/11153)
- We slightly improved the duplicate check if ISBNs are present. [#8885](https://github.com/JabRef/jabref/issues/8885)
- JabRef no longer downloads HTML files of websites when a PDF was not found. [#10149](https://github.com/JabRef/jabref/issues/10149)
- We added the HTTP message (in addition to the response code) if an error is encountered. [#11341](https://github.com/JabRef/jabref/pull/11341)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class IsbnFetcher implements EntryBasedFetcher, IdBasedFetcher {
private static final Pattern NEWLINE_SPACE_PATTERN = Pattern.compile("\\n|\\r\\n|\\s");
protected final ImportFormatPreferences importFormatPreferences;
private final List<AbstractIsbnFetcher> retryIsbnFetcher;
private final GvkFetcher gvkIbsnFetcher;
private final GvkFetcher gvkIsbnFetcher;

public IsbnFetcher(ImportFormatPreferences importFormatPreferences) {
this.importFormatPreferences = importFormatPreferences;
OpenLibraryIsbnFetcher openLibraryIsbnFetcher = new OpenLibraryIsbnFetcher(importFormatPreferences);
this.gvkIbsnFetcher = new GvkFetcher(importFormatPreferences);
this.gvkIsbnFetcher = new GvkFetcher(importFormatPreferences);
this.retryIsbnFetcher = new ArrayList<>();
this.addRetryFetcher(openLibraryIsbnFetcher);
}
Expand All @@ -63,7 +63,7 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc
identifier = removeNewlinesAndSpacesFromIdentifier(identifier);
Optional<ISBN> isbn = ISBN.parse(identifier);
if (isbn.isPresent()) {
bibEntry = gvkIbsnFetcher.performSearchById(isbn.get().getNormalized());
bibEntry = gvkIsbnFetcher.performSearchById(isbn.get().getNormalized());
}
} catch (FetcherException ex) {
LOGGER.debug("Got a fetcher exception for IBSN search", ex);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/logic/net/URLDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ public URLConnection openConnection() throws IOException {
}

if (connection instanceof HttpURLConnection lConnection) {
// normally, 3xx is redirect
// this does network i/o: GET + read returned headers
int status = lConnection.getResponseCode();

// normally, 3xx is redirect
if ((status == HttpURLConnection.HTTP_MOVED_TEMP)
|| (status == HttpURLConnection.HTTP_MOVED_PERM)
|| (status == HttpURLConnection.HTTP_SEE_OTHER)) {
Expand All @@ -399,13 +400,14 @@ public URLConnection openConnection() throws IOException {
connection = new URLDownload(newUrl).openConnection();
}
if ((status >= 400) && (status < 500)) {
throw new IOException(new FetcherClientException("Encountered HTTP Status code " + status));
LOGGER.info("HTTP {}, details: {}, {}", status, lConnection.getResponseMessage(), lConnection.getContentLength() > 0 ? lConnection.getContent() : "");
throw new IOException(new FetcherClientException("Encountered HTTP %s %s".formatted(status, lConnection.getResponseMessage())));
}
if (status >= 500) {
throw new IOException(new FetcherServerException("Encountered HTTP Status Code " + status));
LOGGER.info("HTTP {}, details: {}, {}", status, lConnection.getResponseMessage(), lConnection.getContentLength() > 0 ? lConnection.getContent() : "");
throw new IOException(new FetcherServerException("Encountered HTTP %s %s".formatted(status, lConnection.getResponseMessage())));
}
}
// this does network i/o: GET + read returned headers
return connection;
}

Expand Down

0 comments on commit e1da33d

Please sign in to comment.