Skip to content

Commit

Permalink
improved error when unable to download cnefe data
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Dec 11, 2024
1 parent eb23bb3 commit 9b190b3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Imports:
httr2,
parallel,
purrr,
rlang,
tools,
utils,
zip
Expand Down
14 changes: 10 additions & 4 deletions R/download_cnefe.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ download_files <- function(files_to_download, progress) {
function(r) inherits(r, "error")
)

# TODO: improve this error
if (any(response_errored)) {
stop("Could not download data for one of the states, uh-oh!")
}
if (any(response_errored)) error_cnefe_download_failed()

return(dest_files)
}
Expand All @@ -125,3 +122,12 @@ perform_requests_in_parallel <- function(requests, dest_files, progress) {
)
}

error_cnefe_download_failed <- function() {
geocodebr_error(
c(
"Could not download CNEFE data for one or more states.",
"i" = "Please try again later."
),
call = rlang::caller_env(n = 2)
)
}
18 changes: 15 additions & 3 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,28 @@
"sameAs": "https://CRAN.R-project.org/package=purrr"
},
"13": {
"@type": "SoftwareApplication",
"identifier": "rlang",
"name": "rlang",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=rlang"
},
"14": {
"@type": "SoftwareApplication",
"identifier": "tools",
"name": "tools"
},
"14": {
"15": {
"@type": "SoftwareApplication",
"identifier": "utils",
"name": "utils"
},
"15": {
"16": {
"@type": "SoftwareApplication",
"identifier": "zip",
"name": "zip",
Expand All @@ -332,7 +344,7 @@
},
"SystemRequirements": null
},
"fileSize": "176.64KB",
"fileSize": "181.875KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/download_cnefe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# errors if could not download the data for one or more states

Code
tester("AL", cache = FALSE)
Condition <geocodebr_error_cnefe_download_failed>
Error in `download_cnefe()`:
! Could not download CNEFE data for one or more states.
i Please try again later.

7 changes: 6 additions & 1 deletion tests/testthat/test-download_cnefe.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ test_that("errors if could not download the data for one or more states", {
}
)

expect_error(tester("AL", cache = FALSE))
expect_error(
tester("AL", cache = FALSE),
class = "geocodebr_error_cnefe_download_failed"
)

expect_snapshot(tester("AL", cache = FALSE), error = TRUE, cnd_class = TRUE)
})

test_that("would download the data of all states if state='all'", {
Expand Down

0 comments on commit 9b190b3

Please sign in to comment.