Skip to content

Commit

Permalink
Move the stop for a clearer error #142
Browse files Browse the repository at this point in the history
The stop located within get_json() was not fully stopping the function leading to a confusing error about a missing column when there was actually no data in the data warehouse for a particular species.  Moving this here stops the function correctly.
  • Loading branch information
chantelwetzel-noaa committed Aug 27, 2024
1 parent 9593eb3 commit 2bb9d03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 0 additions & 8 deletions R/get_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,5 @@ get_json <- function(url) {
httr::content(as = "text", encoding = "UTF-8") |>
jsonlite::fromJSON()

if (!(is.data.frame(out) && NROW(out) > 0)) {
stop(glue::glue(
"\n No data returned by the warehouse for the filters given.
\n Make sure the year range is correct (cannot include -Inf or Inf) for the project selected and the input name is correct,
\n otherwise there may be no data for this species from this project.\n
URL: {url}"
))
}
return(out)
}
9 changes: 9 additions & 0 deletions R/pull_bio.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ pull_bio <- function(
}
bio_pull <- try(get_json(url = url_text))

if (!(is.data.frame(bio_pull))) {
stop(glue::glue(
"\n No data returned by the warehouse for the filters given.
\n Make sure the year range is correct (cannot include -Inf or Inf) for the project selected and the input name is correct,
\n otherwise there may be no data for this species from this project.\n
URL: {url_text}"
))
}

if (!is.data.frame(bio_pull) & !survey %in% c("Triennial", "AFSC.Slope")) {
stop(cat("\nNo data returned by the warehouse for the filters given.
Make sure the year range is correct for the project selected and the input name is correct,
Expand Down

0 comments on commit 2bb9d03

Please sign in to comment.