Skip to content

Commit 57ab8b5

Browse files
authored
Merge pull request #8 from e-kotov/4-mi_sources-fails-on-incorrect-year
add check if returned data source list is empty
2 parents fcf7fc3 + 33f6ec8 commit 57ab8b5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

R/sources.R

+9-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ mi_sources <- function(
6464
httr2::req_perform()
6565

6666
response_data <- httr2::resp_body_json(response, simplifyVector = TRUE) |>
67-
tibble::as_tibble() |>
67+
tibble::as_tibble()
68+
69+
if(nrow(response_data) == 0){
70+
stop(paste0("No sources found for year ", year, ". Please specify a different year."))
71+
}
72+
73+
response_data <- response_data |>
6874
dplyr::rename(
6975
description = .data$f_description,
7076
source_name = .data$f_resource,
@@ -76,6 +82,8 @@ mi_sources <- function(
7682
.data$description
7783
)
7884

85+
86+
7987
return(response_data)
8088
}
8189

0 commit comments

Comments
 (0)