Skip to content

Commit f2779bc

Browse files
committed
better errr message catcher, #42
1 parent 316bdc2 commit f2779bc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

R/zzz.R

+10-2
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@ gist_DELETE <- function(url, auth, headers, ...){
8787
}
8888

8989
process <- function(x){
90-
stop_for_status(x)
90+
stopstatus(x)
9191
stopifnot(x$headers$`content-type` == 'application/json; charset=utf-8')
92-
temp <- content(x, as = "text")
92+
temp <- httr::content(x, as = "text")
9393
jsonlite::fromJSON(temp, FALSE)
9494
}
9595

96+
stopstatus <- function(x) {
97+
if (x$status_code > 203) {
98+
res <- httr::content(x)
99+
errs <- sapply(res$errors, function(z) paste(names(z), z, sep = ": ", collapse = "\n"))
100+
stop(res$message, "\n", errs, call. = FALSE)
101+
}
102+
}
103+
96104
check_auth <- function(x) if(!missing(x)) x else gist_auth()
97105

98106
strextract <- function(str, pattern) {

0 commit comments

Comments
 (0)