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 #35
  • Loading branch information
jmaspons committed Apr 16, 2024
1 parent cff21ee commit 9899125
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 9899125

Please sign in to comment.