Skip to content

Commit

Permalink
Check for body in the reponse before to read it
Browse files Browse the repository at this point in the history
If the response has no body, write and empty file
FIX nealrichardson#35
  • Loading branch information
jmaspons committed Apr 25, 2024
1 parent 96b61db commit 245a90f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions R/capture-requests.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ save_response <- function(response, file, simplify = TRUE) {
ct <- resp_content_type(response)
status <- resp_status(response)
if (simplify && status == 200 && ct %in% names(CONTENT_TYPE_TO_EXT)) {
cont <- resp_body_string(response)
if (ct == "application/json") {
# Prettify
cont <- prettify(cont)
if (length(response$body)) {
cont <- resp_body_string(response)
if (ct == "application/json") {
# Prettify
cont <- prettify(cont)
}
} else {
cont <- character()
}
dst_file <- paste(dst_file, CONTENT_TYPE_TO_EXT[[ct]], sep = ".")
cat_wb(cont, file = dst_file)
Expand Down

0 comments on commit 245a90f

Please sign in to comment.