Skip to content

Commit

Permalink
Merge pull request #7 from krlmlr/b-error-handling
Browse files Browse the repository at this point in the history
Better error handling
  • Loading branch information
psolymos authored Nov 6, 2021
2 parents 69535ec + a7e69d7 commit 0faaa84
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions R/internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,27 @@

## convenience function to handle responses
.cu_process <- function(resp) {
cont_text <- httr::content(resp, "text", encoding = "utf-8")
if (httr::http_error(resp)) {
stop(
sprintf("ClickUp API request failed [%s]\n%s - %s",
httr::status_code(resp), cont$err, cont$ECODE),
call. = FALSE)
if (httr::http_type(resp) == "application/json") {
cont <- jsonlite::fromJSON(cont_text, simplifyVector = FALSE)
stop(
sprintf("ClickUp API request failed [%s]\n%s - %s",
httr::status_code(resp), cont$err, cont$ECODE),
call. = FALSE
)
} else {
stop(
sprintf("ClickUp API request failed [%s]\n%s",
httr::status_code(resp), cont_text),
call. = FALSE
)
}
}
if (httr::http_type(resp) != "application/json") {
stop("API did not return json", call. = FALSE)
}
cont <- jsonlite::fromJSON(
httr::content(resp, "text"),
simplifyVector = FALSE)
cont <- jsonlite::fromJSON(cont_text, simplifyVector = FALSE)
attr(cont, "response") <- resp
class(cont) <- "cu"
cont
Expand Down

0 comments on commit 0faaa84

Please sign in to comment.