Skip to content

Commit

Permalink
Do not return NULL and dont throw errors if no response is recorded
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksanderbl29 committed Nov 22, 2024
1 parent b8a49fb commit d90cae9
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions R/base_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ dawa <- function(section,
)
}

if (httr2::resp_is_error(resp)) {
if (is.null(resp)) {
cli::cli_alert_danger("The API returned a {resp$status_code} error.")
cli::cli_alert_danger("No content will be returned")
}

if (!is.null(format) && !httr2::resp_is_error(resp)) {
if (!is.null(format) && !is.null(resp) && !httr2::resp_is_error(resp)) {
tryCatch(
{
if (format %in% c("geojson", "geojsonz")) {
Expand All @@ -140,22 +140,20 @@ dawa <- function(section,
},
error = function(e) {
cli::cli_alert_danger("Failed to parse response: {e$message}")
return(NULL)
}
)
# nolint start
} else if (httr2::resp_content_type(resp) != "application/json" &&
!httr2::resp_is_error(resp)) {
!is.null(resp) && !httr2::resp_is_error(resp)) {
# nolint end
cli::cli_abort("The API did not return JSON")
} else if (!httr2::resp_is_error(resp)) {
} else if (!is.null(resp) && !httr2::resp_is_error(resp)) {
tryCatch(
{
return(resp |> httr2::resp_body_json())
},
error = function(e) {
cli::cli_alert_danger("Failed to parse response: {e$message}")
return(NULL)
}
)
}
Expand Down

0 comments on commit d90cae9

Please sign in to comment.