Skip to content

Commit

Permalink
better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
evanodell committed Feb 3, 2020
1 parent 7047fa6 commit d2515bf
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nomisr
Type: Package
Title: Access 'Nomis' UK Labour Market Data
Version: 0.4.1
Version: 0.4.1.9000
Authors@R: c(
person(
"Evan", "Odell", email = "evanodell91@gmail.com", role = c("aut", "cre"),
Expand Down Expand Up @@ -30,7 +30,7 @@ Imports:
utils,
rsdmx,
rlang
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
Suggests:
knitr,
rmarkdown,
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@


# nomisr 0.4.1.9000

* Error handling improvements when using non-existent parameters, and clarifies
error messages when no data is available for a given query.


# nomisr 0.4.1

* Adding `query_id` parameter to `nomis_get_data()`
Expand Down
7 changes: 7 additions & 0 deletions R/data_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ nomis_get_data <- function(id, time = NULL, date = NULL, geography = NULL,
first_df <- nomis_get_data_util(query)

names(first_df) <- toupper(names(first_df))

if (nrow(first_df) <= 0) {
stop("The API request did not return any results. ",
"Please check your parameters.",
call. = FALSE
)
}

if (as.numeric(first_df$RECORD_COUNT)[1] >= max_length) {
# if amount available is over the limit of 15 total calls at a time
Expand Down
9 changes: 8 additions & 1 deletion R/utils-get-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@ nomis_get_data_util <- function(query) {
)
},
error = function(cond) {
err <- conditionMessage(cond)
if (startsWith(err, "Cannot read file")) {
message("It is likely you have included a parameter that is ",
"not available to query in this dataset.\n\n",
"Here's the original error message:\n", cond)
} else {
message(
"It is likely that you have been automatically rate limited ",
"by the Nomis API.\n",
"You can make smaller data requests, or try again later.\n\n",
"Here's the original error message:\n", cond
)
}

return(NA)
}, warning = function(cond) {
stop("The API request did not return any results.\n",
stop("The API request did not return any results. ",
"Please check your parameters.",
call. = FALSE
)
Expand Down
2 changes: 1 addition & 1 deletion man/nomis_content_type.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions man/nomis_get_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/nomis_get_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/nomis_search.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tests/testthat/test_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ test_that("nomis_get_data return expected format", {
id = "NM_1_1", time = "latest",
measures = c(20100, 20201), sex = 0,
exclude_missing = FALSE, geography = "TYPE499"
))

),
"The API request did not return any results. Please check your parameters.")

x_select <- nomis_get_data(
id = "NM_168_1", time = "latest",
geography = "2013265925", sex = "0",
Expand Down

0 comments on commit d2515bf

Please sign in to comment.