Skip to content

Commit

Permalink
handle case where error is present in json
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahParry committed Feb 12, 2024
1 parent 10efe37 commit 61f1991
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# arcgisutils (development version)

- `parse_esri_json()` will return an empty `data.frame` in the presence of empty results
- `parse_esri_json()` will return an empty `data.frame` in the presence of empty results an error. If an error is present, the error is reported
- Breaking change to how authorization tokens are handled
- Tokens are now stored in internal environment `token_env`
- `set_auth_token()` removed in favor of `set_arc_token()`
Expand Down
5 changes: 5 additions & 0 deletions R/util-parse-esri-json.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ parse_esri_json <- function(string, ...) {
# extract the geometry features
fts_raw <- b_parsed[["features"]]

if (is.null(fts_raw)) {
report_errors(b_parsed)
return(data.frame())
}

# if this is a logical vector of length one we need to abort
if (is.logical(fts_raw) && length(fts_raw) == 1L) return(data.frame())

Expand Down
24 changes: 24 additions & 0 deletions R/utils-requests.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ detect_errors <- function(response, error_call = rlang::caller_env()) {
}
}

#' @keywords internal
#' @noRd
report_errors <- function(response, error_call = rlang::caller_env()) {
e <- response[["error"]]
if (!is.null(e)) {
err_msg <- strwrap(
paste0(" Error", e$messageCode, ": ", e$message),
prefix = " ",
initial = ""
)

full_msg <- c(
"Status code: ",
response[["error"]][["code"]],
"\n",
paste0(err_msg, collapse = "\n")
)

rlang::warn(
paste0(full_msg, collapse = ""),
call = error_call
)
}
}

#' Set user-agent for arcgisutils
#'
Expand Down

0 comments on commit 61f1991

Please sign in to comment.