From f001256886c237faacb8810f1caa3d7d3671bfaa Mon Sep 17 00:00:00 2001 From: DohaRamadan <77820526+DohaRamadan@users.noreply.github.com> Date: Mon, 28 Aug 2023 02:00:22 +0300 Subject: [PATCH 1/5] added error specific messages --- .../gui/fieldeditors/LinkedFileViewModel.java | 22 +++++++++++++++++-- .../importer/FetcherClientException.java | 10 +++++++++ .../importer/FetcherServerException.java | 10 +++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 8124240b4a2..69b7c10a7c4 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -43,6 +43,8 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.externalfiles.LinkedFileHandler; +import org.jabref.logic.importer.FetcherClientException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.logic.importer.Importer; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.PdfContentImporter; @@ -472,8 +474,24 @@ public void download() { Localization.lang("Fulltext for") + ": " + entry.getCitationKey().orElse(Localization.lang("New entry"))); downloadTask.showToUser(true); downloadTask.onFailure(ex -> { - LOGGER.error("Error downloading", ex); - dialogService.showErrorDialogAndWait(Localization.lang("Error downloading"), ex); + LOGGER.error("Error downloading from URL: " + urlDownload, ex); + String fetcherExceptionMessage = ex.getMessage(); + int statusCode; + if (ex instanceof FetcherClientException clientException) { + statusCode = clientException.getStatusCode(); + if (statusCode == 401) { + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("401 Unauthorized: Access Denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance.") + "\nURL: " + urlDownload + "\n" + fetcherExceptionMessage); + } else if (statusCode == 403) { + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("403 Forbidden: Access Denied. You do not have permission to access this resource. Please contact the administrator for assistance or try a different action.") + "\nURL: " + urlDownload + "\n" + fetcherExceptionMessage); + } else if (statusCode == 404) { + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("404 Not Found Error: The requested resource could not be found. It seems that the file you are trying to download is not available or has been moved. Please verify the URL and try again. If you believe this is an error, please contact the administrator for further assistance.") + "\nURL: " + urlDownload + "\n" + fetcherExceptionMessage); + } + } else if (ex instanceof FetcherServerException serverException) { + statusCode = serverException.getStatusCode(); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("Error downloading form URL. Cause is likely the server side. HTTP Error ") + statusCode + "\n" + fetcherExceptionMessage + "\nURL: " + urlDownload + "\nPlease try again later or contact the server administrator."); + } else { + dialogService.showErrorDialogAndWait(Localization.lang("Failed to download from URL"), "Error message: " + fetcherExceptionMessage + "\nURL: " + urlDownload + "\nPlease check the URL and try again."); + } }); taskExecutor.execute(downloadTask); } catch (MalformedURLException exception) { diff --git a/src/main/java/org/jabref/logic/importer/FetcherClientException.java b/src/main/java/org/jabref/logic/importer/FetcherClientException.java index 8f74e23871e..ada85e02903 100644 --- a/src/main/java/org/jabref/logic/importer/FetcherClientException.java +++ b/src/main/java/org/jabref/logic/importer/FetcherClientException.java @@ -4,11 +4,17 @@ * Should be thrown when you encounter an HTTP status code error >= 400 and < 500. */ public class FetcherClientException extends FetcherException { + private int statusCode; public FetcherClientException(String errorMessage, Throwable cause) { super(errorMessage, cause); } + public FetcherClientException(String errorMessage, Throwable cause, int statusCode) { + super(errorMessage, cause); + this.statusCode = statusCode; + } + public FetcherClientException(String errorMessage) { super(errorMessage); } @@ -16,4 +22,8 @@ public FetcherClientException(String errorMessage) { public FetcherClientException(String errorMessage, String localizedMessage, Throwable cause) { super(errorMessage, localizedMessage, cause); } + + public int getStatusCode() { + return statusCode; + } } diff --git a/src/main/java/org/jabref/logic/importer/FetcherServerException.java b/src/main/java/org/jabref/logic/importer/FetcherServerException.java index 537d71ff530..7b657553b5f 100644 --- a/src/main/java/org/jabref/logic/importer/FetcherServerException.java +++ b/src/main/java/org/jabref/logic/importer/FetcherServerException.java @@ -3,11 +3,17 @@ * Should be thrown when you encounter a http status code error >= 500 */ public class FetcherServerException extends FetcherException { + private int statusCode; public FetcherServerException(String errorMessage, Throwable cause) { super(errorMessage, cause); } + public FetcherServerException(String errorMessage, Throwable cause, int statusCode) { + super(errorMessage, cause); + this.statusCode = statusCode; + } + public FetcherServerException(String errorMessage) { super(errorMessage); } @@ -15,4 +21,8 @@ public FetcherServerException(String errorMessage) { public FetcherServerException(String errorMessage, String localizedMessage, Throwable cause) { super(errorMessage, localizedMessage, cause); } + + public int getStatusCode() { + return statusCode; + } } From 1c931c0ea62681a0f0ad734af82b52010a3925eb Mon Sep 17 00:00:00 2001 From: DohaRamadan <77820526+DohaRamadan@users.noreply.github.com> Date: Mon, 28 Aug 2023 10:19:18 +0300 Subject: [PATCH 2/5] Fixed error messages --- .../gui/fieldeditors/LinkedFileViewModel.java | 29 ++++++++++--------- src/main/resources/l10n/JabRef_en.properties | 7 +++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 69b7c10a7c4..9cc026fcae4 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -480,27 +480,28 @@ public void download() { if (ex instanceof FetcherClientException clientException) { statusCode = clientException.getStatusCode(); if (statusCode == 401) { - dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("401 Unauthorized: Access Denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance.") + "\nURL: " + urlDownload + "\n" + fetcherExceptionMessage); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("401 Unauthorized: Access Denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance.\nURL: %0 \n %1", urlDownload.getSource(), fetcherExceptionMessage)); } else if (statusCode == 403) { - dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("403 Forbidden: Access Denied. You do not have permission to access this resource. Please contact the administrator for assistance or try a different action.") + "\nURL: " + urlDownload + "\n" + fetcherExceptionMessage); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("403 Forbidden: Access Denied. You do not have permission to access this resource. Please contact the administrator for assistance or try a different action.\nURL: %0 \n %1", urlDownload.getSource(), fetcherExceptionMessage)); } else if (statusCode == 404) { - dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("404 Not Found Error: The requested resource could not be found. It seems that the file you are trying to download is not available or has been moved. Please verify the URL and try again. If you believe this is an error, please contact the administrator for further assistance.") + "\nURL: " + urlDownload + "\n" + fetcherExceptionMessage); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("404 Not Found Error: The requested resource could not be found. It seems that the file you are trying to download is not available or has been moved. Please verify the URL and try again. If you believe this is an error, please contact the administrator for further assistance.\nURL: %0 \n %1", urlDownload.getSource(), fetcherExceptionMessage)); } } else if (ex instanceof FetcherServerException serverException) { statusCode = serverException.getStatusCode(); - dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("Error downloading form URL. Cause is likely the server side. HTTP Error ") + statusCode + "\n" + fetcherExceptionMessage + "\nURL: " + urlDownload + "\nPlease try again later or contact the server administrator."); - } else { - dialogService.showErrorDialogAndWait(Localization.lang("Failed to download from URL"), "Error message: " + fetcherExceptionMessage + "\nURL: " + urlDownload + "\nPlease check the URL and try again."); - } - }); - taskExecutor.execute(downloadTask); - } catch (MalformedURLException exception) { - dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to download from URL"), + Localization.lang("Error downloading form URL. Cause is likely the server side. HTTP Error %0 \n %1 \nURL: %2 \nPlease try again later or contact the server administrator.", statusCode, fetcherExceptionMessage, urlDownload.getSource())); + } else { + dialogService.showErrorDialogAndWait(Localization.lang("Failed to download from URL"), Localization.lang("Error message: %0 \nURL: %1 \nPlease check the URL and try again.", fetcherExceptionMessage, urlDownload.getSource())); + } + }); + taskExecutor.execute(downloadTask); + } catch (MalformedURLException exception) { + dialogService.showErrorDialogAndWait(Localization.lang("Invalid URL"), exception); + } } - } - public boolean checkSSLHandshake(URLDownload urlDownload) { - try { + public boolean checkSSLHandshake(URLDownload urlDownload) { + try { urlDownload.canBeReached(); } catch (kong.unirest.UnirestException ex) { if (ex.getCause() instanceof javax.net.ssl.SSLHandshakeException) { diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 35300de1883..db2df162c54 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2564,3 +2564,10 @@ Automatically\ search\ and\ show\ unlinked\ files\ in\ the\ entry\ editor=Automa File\ "%0"\ cannot\ be\ added\!=File "%0" cannot be added! Illegal\ characters\ in\ the\ file\ name\ detected.\nFile\ will\ be\ renamed\ to\ "%0"\ and\ added.=Illegal characters in the file name detected.\nFile will be renamed to "%0" and added. Rename\ and\ add=Rename and add + +401\ Unauthorized\:\ Access\ Denied.\ You\ are\ not\ authorized\ to\ access\ this\ resource.\ Please\ check\ your\ credentials\ and\ try\ again.\ If\ you\ believe\ you\ should\ have\ access,\ please\ contact\ the\ administrator\ for\ assistance.\nURL\:\ %0\ \n\ %1=401 Unauthorized: Access Denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance.\nURL: %0 \n %1 +403\ Forbidden\:\ Access\ Denied.\ You\ do\ not\ have\ permission\ to\ access\ this\ resource.\ Please\ contact\ the\ administrator\ for\ assistance\ or\ try\ a\ different\ action.\nURL\:\ %0\ \n\ %1=403 Forbidden: Access Denied. You do not have permission to access this resource. Please contact the administrator for assistance or try a different action.\nURL: %0 \n %1 +404\ Not\ Found\ Error\:\ The\ requested\ resource\ could\ not\ be\ found.\ It\ seems\ that\ the\ file\ you\ are\ trying\ to\ download\ is\ not\ available\ or\ has\ been\ moved.\ Please\ verify\ the\ URL\ and\ try\ again.\ If\ you\ believe\ this\ is\ an\ error,\ please\ contact\ the\ administrator\ for\ further\ assistance.\nURL\:\ %0\ \n\ %1=404 Not Found Error: The requested resource could not be found. It seems that the file you are trying to download is not available or has been moved. Please verify the URL and try again. If you believe this is an error, please contact the administrator for further assistance.\nURL: %0 \n %1 +Error\ downloading\ form\ URL.\ Cause\ is\ likely\ the\ server\ side.\ HTTP\ Error\ %0\ \n\ %1\ \nURL\:\ %2\ \nPlease\ try\ again\ later\ or\ contact\ the\ server\ administrator.=Error downloading form URL. Cause is likely the server side. HTTP Error %0 \n %1 \nURL: %2 \nPlease try again later or contact the server administrator. +Error\ message\:\ %0\ \nURL\:\ %1\ \nPlease\ check\ the\ URL\ and\ try\ again.=Error message: %0 \nURL: %1 \nPlease check the URL and try again. +Failed\ to\ download\ from\ URL=Failed to download from URL From b170d237a0f0359d74045678d432bd0951455d5e Mon Sep 17 00:00:00 2001 From: Doha Ramadan <77820526+DohaRamadan@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:22:44 +0300 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33179c8d7c7..fd66507e2b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ## [Unreleased] ### Added +- We added an error-specific message for when a download from a URL fails.[#9826](https://github.com/JabRef/jabref/issues/9826). ### Changed From 64a1708cf165c189048efc74cf6f899696361134 Mon Sep 17 00:00:00 2001 From: Doha Ramadan <77820526+DohaRamadan@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:23:03 +0300 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd66507e2b1..c9b45e91de4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ## [Unreleased] ### Added -- We added an error-specific message for when a download from a URL fails.[#9826](https://github.com/JabRef/jabref/issues/9826). +- We added an error-specific message for when a download from a URL fails[#9826](https://github.com/JabRef/jabref/issues/9826). ### Changed From 341e041dfbf0ff0e664cb06412449ab90303616b Mon Sep 17 00:00:00 2001 From: Doha Ramadan <77820526+DohaRamadan@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:37:28 +0300 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9b45e91de4..b085f3e306a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ## [Unreleased] ### Added + - We added an error-specific message for when a download from a URL fails[#9826](https://github.com/JabRef/jabref/issues/9826). ### Changed