Skip to content

Commit

Permalink
Add http response message (and log some details)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed May 27, 2024
1 parent 7e537a6 commit 0c90c3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 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.

### Fixed

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 0c90c3b

Please sign in to comment.