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

More verbose httr error message for get_file() #31

Closed
EdJeeOnGitHub opened this issue Dec 1, 2019 · 2 comments · Fixed by #30
Closed

More verbose httr error message for get_file() #31

EdJeeOnGitHub opened this issue Dec 1, 2019 · 2 comments · Fixed by #30
Labels
data-download Functions that are about downloading, not uploading, data

Comments

@EdJeeOnGitHub
Copy link
Contributor

I often find get_file() errors since the API can't return a certain file format. Since the dataverse API returns informative messages when a request fails it makes sense to pass this along in R instead of just the default from httr::stop_for_status().

For instance:

library(dataverse)
library(tidyverse)

IPA_dataset <- get_dataset("doi:10.7910/DVN/JGLOZF")
# doi:  https://doi.org/10.7910/DVN/JGLOZF
community_files <- IPA_dataset$files$id %>% 
  map(function(x){
    print(x)
    return(get_file(x))
  })

after the PR will return:

Not Found (HTTP 404). Failed to '/api/v1/access/datafile/2972336' datafile access error: requested optional service (image scaling, format conversion, etc.) is not supported on this datafile.

instead of:

Error in get_file(x) : Not Found (HTTP 404).

@kuriwaki kuriwaki added the data-download Functions that are about downloading, not uploading, data label Dec 3, 2020
@kuriwaki
Copy link
Member

kuriwaki commented Dec 28, 2020

I like this feature very much. (See below for a reprex).

Your current IPA example fails to give the intended error (i.e. it actually passes without any error messages). It's not clear if it should fail: your example trys to download a Word Doc and indeed
https://dataverse.harvard.edu/api/access/datafile/2972336?format=original gives that error you posted but
https://dataverse.harvard.edu/api/access/datafile/2972336 but downloads the Word Doc fine. In #39 I changed so that querys/format args are only used when the target is an ingested file.

That was a stopgap and should be revisited... in the meantime, are there any examples of .tab files for which we'd get an informative error message? We can put that in a testthat too.

# Get `ReadMe with Codebook.docx` (https://doi.org/10.7910/DVN/JGLOZF/GYZ7OQ, id = 2972336)
# master branch
library(dataverse)
get_file(2972336, server = "demo.dataverse.org") # wrong server
#> Error in get_file(2972336, server = "demo.dataverse.org"): Not Found (HTTP 404).
# EdJeeOnGitHub fork branch
library(dataverse)
get_file(2972336, server = "demo.dataverse.org") # wrong server
#> Error in get_file(2972336, server = "demo.dataverse.org"): Not Found (HTTP 404). Failed to API endpoint does not exist on this server. Please check your code for typos, or consult our API guide at http://guides.dataverse.org..

Created on 2020-12-28 by the reprex package (v0.3.0)

@kuriwaki kuriwaki linked a pull request Dec 28, 2020 that will close this issue
@EdJeeOnGitHub
Copy link
Contributor Author

Thanks!

Back in Nov 2019 it was definitely throwing errors but things seem to have changed quite a bit since then - I think the pull request was meant to be incorporated some time ago but seems to have fallen through the cracks.

I haven't touched any dataverse data in a while now so don't have any handy candidates for test cases I'm afraid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data-download Functions that are about downloading, not uploading, data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants