Skip to content

Commit

Permalink
Feat/41 check for empty downloads (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAxthelm authored Apr 23, 2024
1 parent 4a1c606 commit 847dd09
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/get_currency_exchange_rates.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ get_currency_exchange_rates <-
year
)

httr2::request(url) %>%
raw_data <- httr2::request(url) %>%
httr2::req_headers("Accept" = "application/json") %>%
httr2::req_timeout(max_seconds) %>%
httr2::req_retry(
Expand All @@ -47,7 +47,14 @@ get_currency_exchange_rates <-
httr2::resp_body_json(simplifyVector = TRUE) %>%
.[["CompactData"]] %>%
.[["DataSet"]] %>%
.[["Series"]] %>%
.[["Series"]]

if (is.null(raw_data)) {
log_error("No data found for the specified quarter: {quarter}.")
stop("No data found for the specified quarter.")
}

raw_data %>%
dplyr::rowwise() %>%
dplyr::mutate(Obs = list(as.data.frame(.data$Obs))) %>%
tidyr::unnest(cols = "Obs") %>%
Expand Down
8 changes: 8 additions & 0 deletions R/get_index_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ get_index_regions <- function() {
ct$get("JSON.stringify(chartDataDMJson)"),
flatten = TRUE
)
if (length(dm_data$categories) == 0L) {
log_error("No data found for Developed Markets.")
stop("No data found for Developed Markets.")
}

log_debug("extracting data from script.")
dm_countries <- c()
Expand Down Expand Up @@ -72,6 +76,10 @@ get_index_regions <- function() {
ct$get("JSON.stringify(chartDataEMJson)"),
flatten = TRUE
)
if (length(data$categories) == 0L) {
log_error("No data found for Emerging Markets.")
stop("No data found for Emerging Markets.")
}

log_debug("extracting data from script.")
em_countries <- c()
Expand Down
5 changes: 5 additions & 0 deletions R/get_ishares_index_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ get_ishares_index_data <- function(url, name, as_of_date) {
# JSON string contains (illegal) UTF8 byte-order-mark!
jsonlite::fromJSON(data_path)$aaData
)
if(length(raw_data) == 0L) {
log_error("No data found for the specified date.")
stop("No data found for the specified date.")
}


fixed_data <- fix_data(raw_data, data_names)

Expand Down

0 comments on commit 847dd09

Please sign in to comment.