Skip to content

Commit 19dffbd

Browse files
make arc rest more tolerant of failures
1 parent 79e2ae7 commit 19dffbd

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

R/arcrest_tools.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ query_usgs_arcrest <- function(AOI = NULL, ids = NULL,
170170
outFields = "*",
171171
f = "geojson")
172172

173-
out[[i]] <- hgf_sf(URL, body = post_body, encode = "form")
173+
out[i] <- list(hgf_sf(URL, body = post_body, encode = "form"))
174174
}
175175

176176
if(inherits(out[[1]], "data.frame")) {

tests/testthat/test_arcrest.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,31 @@ test_that("basic 3dhp service requests", {
6666
expect_s3_class(test_data, "sf")
6767
})
6868
})
69+
70+
test_that("query_usgs_arcrest degrades gracefully when the feature fetch fails", {
71+
72+
AOI_new <- sf::st_as_sfc(sf::st_bbox(c(xmin = -89.5, ymin = 43.0,
73+
xmax = -89.4, ymax = 43.1),
74+
crs = "+proj=longlat +datum=WGS84 +no_defs"))
75+
76+
# fully mocked at the internal-helper level (no fixtures/network) so a
77+
# fresh, never-memoised call signature isn't required
78+
testthat::local_mocked_bindings(
79+
get_arcrest_service_info = function(...) list(
80+
url_base = "https://example.com/MapServer/",
81+
all_layers = list(layers = list(list(id = 0, name = "Flowline",
82+
type = "Feature Layer"))),
83+
id = "id3dhp"),
84+
hgf_json = function(...) list(objectIds = list(1, 2, 3)),
85+
# simulates the feature-fetch request failing (e.g. an HTTP 504) after
86+
# the objectIds lookup already succeeded
87+
hgf_sf = function(...) NULL,
88+
.package = "hydrogeofetch")
89+
90+
expect_warning(
91+
out <- hydrogeofetch:::query_usgs_arcrest(
92+
AOI_new, service = "3DHP_all", type = "flowline"),
93+
"features found")
94+
95+
expect_null(out)
96+
})

0 commit comments

Comments
 (0)