diff --git a/R/zzz.R b/R/zzz.R index 341bed7..4e91f5b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,19 +3,31 @@ sc <- function(x){ } return_obj <- function(x, y){ + y <- err_hand(y) x <- match.arg(x, c('response', 'list', 'table', 'data.frame')) if (x == 'response') { y } else { - out <- content(y, as = "text") if (x == 'list') { - fromJSON(out, simplifyVector = FALSE, flatten = TRUE) + fromJSON(y, simplifyVector = FALSE, flatten = TRUE) } else { - fromJSON(out, flatten = TRUE) + fromJSON(y, flatten = TRUE) } } } +# check if stupid single left bracket returned +err_hand <- function(z) { + tmp <- content(z, "text") + if (identical(tmp, "[")) { + q <- parse_url(z$request$opts$url)$query + q <- paste0("\n - ", paste(names(q), q, sep = "="), collapse = "") + stop("The following query had no results:\n", q, call. = FALSE) + } else { + tmp + } +} + give_noiter <- function(as, url, endpt, args, ...) { tmp <- return_obj(as, query(paste0(url, endpt), args, ...)) switch(as,