Skip to content

Commit b51e9dc

Browse files
committed
Tests for error responses with html body
1 parent 7c6bf23 commit b51e9dc

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

R/osmapiR_request.R

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ parse_html_error_body <- function(resp) {
3434
html <- httr2::resp_body_html(resp)
3535
msg <- xml2::xml_children(xml2::xml_find_all(html, ".//div"))
3636
out <- xml2::xml_text(msg)
37+
out <- c(
38+
out,
39+
paste(
40+
"Please, open an issue at `https://github.com/jmaspons/osmapiR/issues`",
41+
"and report the output of `httr2::last_response()`."
42+
)
43+
)
3744

3845
return(out)
3946
}

inst/WORDLIST

+1
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ vals
388388
vapply
389389
VAZUTwcmHJLwDEX
390390
Vectorized
391+
vectorizing
391392
VignetteBuilder
392393
Visca
393394
VORx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
structure(list(method = "GET", url = "osm.org/api/0.6/err", status_code = 404L,
2+
headers = structure(list(vary = "Accept-Language,Origin",
3+
`referrer-policy` = "strict-origin-when-cross-origin",
4+
`x-permitted-cross-domain-policies` = "none", `x-xss-protection` = "1; mode=block",
5+
`content-language` = "en", `x-request-id` = "REDACTED",
6+
link = "</assets/errors-f22ac01f5c336b3c39aad5b6efe71abb4c85eaa779786e388c0f963caaa8f43e.css>; rel=preload; as=style; nopush",
7+
`x-download-options` = "noopen", `x-runtime` = "0.015498",
8+
`x-frame-options` = "sameorigin", `x-content-type-options` = "nosniff",
9+
`content-security-policy` = "default-src 'self'; child-src 'self'; connect-src 'self' matomo.openstreetmap.org; font-src 'none'; form-action 'self'; frame-ancestors 'self'; frame-src 'self'; img-src 'self' data: www.gravatar.com *.wp.com tile.openstreetmap.org *.tile.openstreetmap.org *.tile.thunderforest.com tile.tracestrack.com *.openstreetmap.fr matomo.openstreetmap.org https://openstreetmap-user-avatars.s3.dualstack.eu-west-1.amazonaws.com https://openstreetmap-gps-images.s3.dualstack.eu-west-1.amazonaws.com; manifest-src 'self'; media-src 'none'; object-src 'self'; script-src 'self' matomo.openstreetmap.org; style-src 'self'; worker-src 'none'",
10+
date = "REDACTED", `x-powered-by` = "Phusion Passenger(R) 6.0.20",
11+
`strict-transport-security` = "max-age=31536000; includeSubDomains; preload",
12+
status = "404 Not Found", `content-type` = "text/html; charset=utf-8",
13+
server = "Apache/2.4.54 (Ubuntu)"), class = "httr2_headers"),
14+
body = charToRaw("<!DOCTYPE html>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n <head>\n <meta charset=\"utf-8\">\n <title>OpenStreetMap</title>\n <link rel=\"stylesheet\" href=\"/assets/errors-f22ac01f5c336b3c39aad5b6efe71abb4c85eaa779786e388c0f963caaa8f43e.css\" media=\"screen\" />\n \n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-57x57-0af2b52ac2b1a8cb0aba42f17aa901bfdedb9174bd978f838e3b3e1dd8602f52.png\" sizes=\"57x57\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-60x60-cff74c9066d8e7fd08b29407712edbae5613cc9a4c03ee0398a89502a6a41d1f.png\" sizes=\"60x60\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-72x72-63c6fdf3ddf65feebac1c0441bf6a378d1e4bde7107f598ae86733c402895eae.png\" sizes=\"72x72\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-76x76-1740d6e7a59521693c496dd8fbe1caf3d5ad302017cb0f5073b6914b4f5b7544.png\" sizes=\"76x76\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-114x114-20ba9df1a8f9b341040d661b7942b7b10288b9b4c4ce0663e10018958dc7f4a8.png\" sizes=\"114x114\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-120x120-c304991e604d1be82639709b96fb87f7b6b6688cc0d04d5f6141604259299648.png\" sizes=\"120x120\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-144x144-fbf20bdf9d2f7c1fe8eb85d7869a9bda285be88c93a39438150f5eb5955758ce.png\" sizes=\"144x144\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-152x152-af45dc979e972cab863517b2cb33a3dcf3e04e02a2eb2734c6f93edc21fa395d.png\" sizes=\"152x152\" />\n<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/assets/apple-touch-icon-180x180-ea6361d7ae5b3f08c6290652ad703fa239364cc09c84873044f3299845f24652.png\" sizes=\"180x180\" />\n<link rel=\"icon\" type=\"image/png\" href=\"/assets/favicon-32x32-99b88fcadeef736889823c8a886b89d8cada9d4423a49a27de29bacc0a6bebd1.png\" sizes=\"32x32\" />\n<link rel=\"icon\" type=\"image/png\" href=\"/assets/favicon-194x194-79d3fb0152c735866e64b1d7535d504483cd13c2fad0131a6142bd9629d30de2.png\" sizes=\"194x194\" />\n<link rel=\"icon\" type=\"image/png\" href=\"/assets/favicon-96x96-6ffbc38962fddb870f9577b76430a0ee4db5fb4eca485f850cd45436d7f3eb87.png\" sizes=\"96x96\" />\n<link rel=\"icon\" type=\"image/png\" href=\"/assets/android-chrome-192x192-f970b9be3965dfda6ea9481b305c39b2ec794e296f802235e30d4671f0f896e1.png\" sizes=\"192x192\" />\n<link rel=\"icon\" type=\"image/png\" href=\"/assets/favicon-16x16-474476c1b2381628a81361a9e2bf04b936d21f77c59e84b48c6c69ea376fb6cf.png\" sizes=\"16x16\" />\n<link rel=\"mask-icon\" href=\"/assets/tab-icon-3e700a12d38a1bba06d674ed663824232025cd6b0ca5c439c846740a7468b302.svg\" color=\"#7ebc6f\">\n<link rel=\"manifest\" href=\"/assets/manifest-b2cc1407226d3e16e6149425747239c259fbe44b41bff3aca36ca6d9e56a6e18.json\">\n<meta name=\"msapplication-config\" content=\"/assets/browserconfig-c59184dc0264731151cbf50ae58f7fa8ae5153138013f125203e1193800f862f.xml\">\n<meta name=\"msapplication-TileColor\" content=\"#00a300\">\n<meta name=\"msapplication-TileImage\" content=\"/assets/mstile-144x144-02723f6f7cb2c18e6f8041c93f80982decb52b24a7e447477bc2ce3136d75806.png\">\n<meta name=\"theme-color\" content=\"#ffffff\">\n<meta name=\"turbo-refresh-method\" content=\"morph\">\n<meta name=\"turbo-refresh-scroll\" content=\"preserve\">\n<link href=\"https://www.openstreetmap.org/404\" rel=\"canonical\" />\n<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"OpenStreetMap Search\" href=\"/assets/osm-42b7b3fbcee2193e455a773db6cd3d34a2f48ca94547fed54901dd9d8307b02b.xml\">\n<meta name=\"description\" content=\"OpenStreetMap is the free wiki world map.\">\n<meta property=\"og:site_name\" content=\"OpenStreetMap\">\n<meta property=\"og:title\" content=\"OpenStreetMap\">\n<meta property=\"og:type\" content=\"website\">\n<meta property=\"og:image\" content=\"osm.org/assets/osm_logo_256-ed028f90468224a272961c380ecee0cfb73b8048b34f4b4b204b7f0d1097875d.png\">\n<meta property=\"og:image:secure_url\" content=\"osm.org/assets/osm_logo_256-ed028f90468224a272961c380ecee0cfb73b8048b34f4b4b204b7f0d1097875d.png\">\n<meta property=\"og:url\" content=\"osm.org/404\">\n<meta property=\"og:description\" content=\"OpenStreetMap is a map of the world, created by people like you and free to use under an open license.\">\n\n </head>\n <body>\n <a href=\"/\">\n <img srcset=\"/assets/osm_logo-4afddaae0230a5a46687fdc751ed256dfdccde144118cb02a7d7960f207a4b92.svg\" alt=\"OpenStreetMap logo\" class=\"logo\" src=\"/assets/osm_logo-9391021d40a7acdafd2ac5d5622dfe0e469c61421fdb2975365c183f5edaa270.png\" />\n </a>\n <div class=\"details\">\n <h1>File not found</h1>\n<p>Couldn&#39;t find a file/directory/API operation by that name on the OpenStreetMap server (HTTP 404)</p>\n<p>Feel free to <a title=\"Various contact channels explained\" href=\"https://wiki.openstreetmap.org/wiki/Contact\">contact</a> the OpenStreetMap community if you have found a broken link / bug. Make a note of the exact URL of your request.</p>\n\n\n </div>\n </body>\n</html>\n"),
15+
cache = new.env(parent = emptyenv())), class = "httr2_response")

tests/testthat/test-osmapiR_request.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ test_that("error handling works", {
2323
"The user doesn't own that changeset"
2424
)
2525

26-
## TODO: look for error responses with body as text/html
26+
## Message in the body (content-type: text/html)
27+
expect_error(
28+
osmapi_request() |> httr2::req_url_path_append("err") |> httr2::req_perform(),
29+
"File not found"
30+
)
31+
# expect_error(osm_delete_gpx(1:2)) may be fixed in the future by vectorizing api calls
2732
})
2833
})

0 commit comments

Comments
 (0)