From e1da33d4bcf5c91f155a9459aa42d05f81aedcd5 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 27 May 2024 21:48:12 +0200 Subject: [PATCH] Add http response message (and log some details) (#11341) * Add http response message (and log some details) * Fix typo * Update CHANGELOG.md --- CHANGELOG.md | 1 + .../importer/fetcher/isbntobibtex/IsbnFetcher.java | 6 +++--- src/main/java/org/jabref/logic/net/URLDownload.java | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9ec3e1a266..5cc54e96d63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java index c449320075d..7df0fb6fab5 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/isbntobibtex/IsbnFetcher.java @@ -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 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); } @@ -63,7 +63,7 @@ public Optional performSearchById(String identifier) throws FetcherExc identifier = removeNewlinesAndSpacesFromIdentifier(identifier); Optional 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); diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 2baf9dcee00..8662eafce7d 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -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)) { @@ -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; }