AtlasOfLivingAustralia / galah-R

Query living atlases from R
https://galah.ala.org.au
39 stars 3 forks source link

Improve error messages when API query fails for international atlases #94

Closed daxkellie closed 2 years ago

daxkellie commented 2 years ago

Occassionally other international atlases may fail to return download queries while they are upgrading their services. Error messages should be improved to make it clearer to users that the error is caused by a failed API call rather than with {galah} or with their query

library(galah)  
library(taxize) 

galah_config(atlas = "UK") # set to NBN Atlas

# get id for wild boar (Sus Scrofa)

id <- get_nbnid("Sus Scrofa", rows = 1)
#> ==  1 queries  ===============
#> 
#> Retrieving data for taxon 'Sus Scrofa'
#> v  Found:  Sus Scrofa
#> ==  Results  =================
#> 
#> * Total: 1 
#> * Found: 1 
#> * Not Found: 0

ala_counts(taxa = id) # counts returned
#> [1] 755
occ <- ala_occurrences(taxa = id) # occurrence records not returned
#> This query will return 755 records
#>   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
#> Error in parse_url(status$downloadUrl): length(url) == 1 is not TRUE

Additionally, it appears that ala_occurrences() may be supplying better error messages for some, but not all, errors of this type

# get id for fox

id <- get_nbnid("vulpes vulpes", rows = 1)
#> ==  1 queries  ===============
#> 
#> Retrieving data for taxon 'vulpes vulpes'
#> v  Found:  vulpes vulpes
#> ==  Results  =================
#> 
#> * Total: 1 
#> * Found: 1 
#> * Not Found: 0

ala_counts(taxa = id) # counts returned
#> [1] 149388
occ <- ala_occurrences(taxa = id) # occurrence records not returned
#> This query will return 149388 records
#>   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
#> There was an error reading the occurrence data; possibly no data was returned. This may be because
#> no valid column names have been provided. To check whether column names are valid, use `search_fields()`
#> Error in names(df) <- rename_columns(names(df), type = "occurrence"): names() applied to a non-vector

Created on 2021-08-26 by the reprex package (v2.0.1)

daxkellie commented 2 years ago

Relates to better messages when API fails, which are implemented as per issue #119