Skip to content

Commit

Permalink
fix #7 now surfacing error messages for the known cases, and should w…
Browse files Browse the repository at this point in the history
…ork for all others
  • Loading branch information
sckott committed Jan 25, 2024
1 parent cca767d commit 436e006
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
glue,
httr
Suggests:
knitr,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ importFrom(httr,GET)
importFrom(httr,POST)
importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(httr,http_error)
importFrom(httr,http_status)
importFrom(httr,status_code)
importFrom(httr,stop_for_status)
importFrom(httr,timeout)
3 changes: 1 addition & 2 deletions R/cancel.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ proof_cancel <- function() {
proof_header(),
timeout(proofr_env$timeout_sec)
)
# FIXME: better error handling - surface error messages
stop_for_status(response)
stop_for_message(response)
content(response, as = "parsed")
}
13 changes: 13 additions & 0 deletions R/http.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
stop_for_message <- function(response) {
if (http_error(response)) {
parsed <- tryCatch(content(response), error = function(e) e)
if (inherits(parsed, "error")) stop_for_status(response)
if (!is.list(parsed)) stop_for_status(response)
msg <- glue::glue(
"{http_status(response)$reason}",
" (HTTP {status_code(response)})",
" {parsed$message}"
)
stop(msg, call. = FALSE)
}
}
3 changes: 2 additions & 1 deletion R/proofr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## usethis namespace: start
#' @importFrom httr GET POST DELETE add_headers content
#' stop_for_status timeout
#' stop_for_status timeout http_status status_code
#' http_error
## usethis namespace: end
NULL
3 changes: 1 addition & 2 deletions R/start.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ proof_start <- function(pi_name = NULL) {
encode = "json",
timeout(proofr_env$timeout_sec)
)
# FIXME: better error handling - surface error messages
stop_for_status(response)
stop_for_message(response)
content(response, as = "parsed")
}
2 changes: 1 addition & 1 deletion R/status.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ proof_status <- function() {
proof_header(),
timeout(proofr_env$timeout_sec)
)
stop_for_status(response)
stop_for_message(response)
content(response, as = "parsed")
}

0 comments on commit 436e006

Please sign in to comment.