Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when downloading a file fails #9826

Closed
Siedlerchr opened this issue May 1, 2023 · 7 comments · Fixed by #10213
Closed

Improve error message when downloading a file fails #9826

Siedlerchr opened this issue May 1, 2023 · 7 comments · Fixed by #10213
Assignees
Labels
external files FirstTimeCodeContribution Triggers GitHub Greeter Workflow good first issue An issue intended for project-newcomers. Varies in difficulty.

Comments

@Siedlerchr
Copy link
Member

Siedlerchr commented May 1, 2023

Copy the following bibtex code:

@Article{levy_organising_2023,
  author       = {Levy, David L.},
  date         = {2023-04},
  journaltitle = {Environmental Politics},
  title        = {Organising responses to climate change: the politics of mitigation, adaptation and suffering},
  doi          = {10.1080/09644016.2023.2204045},
  issn         = {0964-4016},
  number       = {0},
  pages        = {1--3},
  url          = {https://doi.org/10.1080/09644016.2023.2204045},
  urldate      = {2023-05-01},
  volume       = {0},
  file         = {Full Text PDF:https\://www.tandfonline.com/doi/pdf/10.1080/09644016.2023.2204045:application/pdf},
  publisher    = {Routledge},
  shorttitle   = {Organising responses to climate change},
}

Paste it on the maintable in a new library
See the error message: 403 forbidden

Context:
It's a known issue that sometimes the browser extension shows an error page although the import was successful (and there is an issue already for this).

However, the error dialog on the JabRef side needs improvement: explain what 403 means and suggest solutions (not everyone knows this), and also report the url it tried to download; finally, it should proceed with the import and save the file url just as an linked url in the file field.

Solution:

  1. Improve the error message in
    downloadTask.onFailure(ex -> {
    LOGGER.error("Error downloading", ex);
    dialogService.showErrorDialogAndWait(Localization.lang("Error downloading"), ex);
    });

Include the URL in the error message

For a reference/similar handling, see:

if (exception instanceof FetcherClientException) {
dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.") + "\n" + fetcherExceptionMessage);
} else if (exception instanceof FetcherServerException) {
dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try again later.") + "\n" + fetcherExceptionMessage);
} else {
dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Error message %0", fetcherExceptionMessage));
}
LOGGER.error(String.format("Exception during fetching when using fetcher '%s' with entry id '%s'.", searchId, fetcher), exception);

  1. Store the url in the file field of the corresponding entry

Originally posted by @tobiasdiez in #9816 (comment)

@Siedlerchr Siedlerchr added the good first issue An issue intended for project-newcomers. Varies in difficulty. label May 1, 2023
@github-project-automation github-project-automation bot moved this to Free to take in Good First Issues May 1, 2023
@yerraga
Copy link

yerraga commented May 2, 2023

Hi Team,
I am new contributor,
for this issue I have followed below approach pls find once and pls assign it to me if it is ok

downloadTask.onFailure(ex -> {
    String url = downloadTask.getSource().toString();
    LOGGER.error("Error downloading from URL: " + url, ex);
    String errorMessage = ex.getMessage();
    if (errorMessage.contains("403")) {
        errorMessage = "HTTP Error 403: Forbidden. This may be due to authentication issues or the server blocking your request. Please check your credentials or contact the server administrator.";
    }
    dialogService.showErrorDialogAndWait(Localization.lang("Error downloading from URL"), errorMessage + "\nURL: " + url + "\nPlease check the URL and try again.");
    // store the URL as a linked URL in the file field of the corresponding entry
    FieldEditorViewModel editor = viewModel.getFieldEditorVM(fieldName);
    if (editor instanceof FileFieldEditorViewModel) {
        FileFieldEditorViewModel fileEditor = (FileFieldEditorViewModel) editor;
        fileEditor.addLinkedFile(url, "");
    }
});

@Siedlerchr Siedlerchr added the FirstTimeCodeContribution Triggers GitHub Greeter Workflow label May 2, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

As a general advice for newcomers: check out Contributing for a start. Also, guidelines for setting up a local workspace is worth having a look at.

Feel free to ask here at GitHub, if you have any issue related questions. If you have questions about how to setup your workspace use JabRef's Gitter chat. Try to open a (draft) pull-request early on, so that people can see you are working on the issue and so that they can see the direction the pull request is heading towards. This way, you will likely receive valuable feedback.

@Siedlerchr
Copy link
Member Author

Your approach goes in the right direction. However, as I outlined in the issue, you first need to check the type of the exception if it's a FetcherClientException or a FetcherServerException

I would also add a new field to the FetcherClientException and Server: The status code, so you don't need to check the message but can check the field.

I would check for at least 403 and 404 and maybe as well 401

Second: I already noticed that you don't need to do anything with storing of the url as it is already contained in the file field.

@ThiloteE ThiloteE moved this from Free to take to Reserved in Candidates for University Projects May 2, 2023
@ThiloteE ThiloteE moved this from Free to take to Reserved in Good First Issues May 2, 2023
yerraga added a commit to yerraga/jabref that referenced this issue May 4, 2023
@ThiloteE ThiloteE moved this from Reserved to Under Review in Candidates for University Projects May 14, 2023
@ThiloteE ThiloteE moved this from Reserved to In Progress in Good First Issues Jun 6, 2023
@koppor koppor moved this from Under Review to Free to take in Candidates for University Projects Jul 31, 2023
@koppor koppor moved this from In Progress to Free to take in Good First Issues Jul 31, 2023
@Brandon-z-lu
Copy link

Brandon-z-lu commented Aug 7, 2023

Screenshot 2023-08-07 at 12 06 01 PM

Can this issue be considered resolved?
It seems that this BibTex isn't causing any problems?

@ThiloteE
Copy link
Member

ThiloteE commented Aug 7, 2023

The issue to improve the error message remains. The pull-request seemed promising.
Not sure, if the bibtex entry is really needed to work on this issue.

@DohaRamadan
Copy link
Contributor

Can I work on this?

@ThiloteE ThiloteE moved this from Free to take to Reserved in Good First Issues Aug 26, 2023
@ThiloteE ThiloteE moved this from Free to take to Reserved in Candidates for University Projects Aug 26, 2023
@DohaRamadan
Copy link
Contributor

I'm having trouble reproducing this error, I tried to paste what @Siedlerchr provided, and no error occurred.

@github-project-automation github-project-automation bot moved this from Reserved to Done in Good First Issues Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external files FirstTimeCodeContribution Triggers GitHub Greeter Workflow good first issue An issue intended for project-newcomers. Varies in difficulty.
Projects
Archived in project
5 participants