diff --git a/R/ghcnd.R b/R/ghcnd.R index 597edb96..f196f8a8 100644 --- a/R/ghcnd.R +++ b/R/ghcnd.R @@ -193,23 +193,6 @@ strex <- function(x) str_extract_(x, "[0-9]+") as_tc <- function(x) textConnection(enc2utf8(rawToChar(x))) as_tc_p <- function(x) textConnection(x$parse("latin1")) -GET_retry <- function(url, ..., times = 3) { - cliret <- crul::HttpClient$new(url) - res <- suppressWarnings(cliret$get(...)) - if (res$status_code > 226) { - message("Request failed - Retrying") - stat <- 500 - i <- 0 - while (stat > 226 && i <= times) { - i <- i + 1 - res <- suppressWarnings(cliret$get(...)) - stat <- res$status_code - } - if (res$status_code > 226) stop("Request failed, try again", call. = FALSE) - } - return(res) -} - ghcnd_GET <- function(stationid, ...){ ghcnd_cache$mkdir() fp <- ghcnd_local(stationid) diff --git a/R/zzz.r b/R/zzz.r index 41e03744..4a0ea8b3 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -219,3 +219,20 @@ assert <- function(x, y) { } } } + +GET_retry <- function(url, ..., times = 3) { + cliret <- crul::HttpClient$new(url) + res <- suppressWarnings(cliret$get(...)) + if (res$status_code > 226) { + message("Request failed - Retrying") + stat <- 500 + i <- 0 + while (stat > 226 && i <= times) { + i <- i + 1 + res <- suppressWarnings(cliret$get(...)) + stat <- res$status_code + } + if (res$status_code > 226) stop("Request failed, try again", call. = FALSE) + } + return(res) +}