Skip to content

Commit

Permalink
Merge pull request #180 from annnvv/httr_retry
Browse files Browse the repository at this point in the history
replace httr::GET() with httr::RETRY()
  • Loading branch information
antagomir committed Apr 21, 2020
2 parents d6b3b5e + 5a48da8 commit 2efe73d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions R/get_eurostat_geospatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Please check your connection and/or review your proxy settings")

if (nuts_level %in% c("0","all")){
url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_0.geojson")
resp <- GET(url)
resp <- RETRY("GET", url, terminate_on = c(404))
if (httr::http_error(resp)) {
stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url))
} else {
Expand All @@ -168,7 +168,7 @@ Please check your connection and/or review your proxy settings")
}
if (nuts_level %in% c("1","all")){
url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_1.geojson")
resp <- GET(url)
resp <- RETRY("GET", url, terminate_on = c(404))
if (httr::http_error(resp)) {
stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url))
} else {
Expand All @@ -177,7 +177,7 @@ Please check your connection and/or review your proxy settings")
}
}
if (nuts_level %in% c("2","all")){
resp <- GET(paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_2.geojson"))
resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_2.geojson"), terminate_on = c(404))
if (httr::http_error(resp)) {
stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url))
} else {
Expand All @@ -186,7 +186,7 @@ Please check your connection and/or review your proxy settings")
}
}
if (nuts_level %in% c("3","all")){
resp <- GET(paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_3.geojson"))
resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_3.geojson"), terminate_on = c(404))
if (httr::http_error(resp)) {
stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url))
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/get_eurostat_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ get_eurostat_json <- function(id, filters = NULL,

# resp <- try(httr::GET(url, ...))
# if (class(resp) == "try-error") { stop(paste("The requested url cannot be found within the get_eurostat_json function:", url)) }
resp <- httr::GET(url)
resp <- httr::RETRY("GET", url, terminate_on = c(404))
if (httr::http_error(resp)) {
stop(paste("The requested url cannot be found within the get_eurostat_json function:", url))
}
Expand Down

0 comments on commit 2efe73d

Please sign in to comment.