Skip to content

Commit dffc72b

Browse files
committed
047 handling http failures
1 parent 225684d commit dffc72b

28 files changed

+988
-70
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: eurlex
22
Type: Package
33
Title: Retrieve Data on European Union Law
4-
Version: 0.4.6
4+
Version: 0.4.7
55
Authors@R: c(person(given = "Michal",
66
family = "Ovadek",
77
role = c("aut", "cre", "cph"),
@@ -12,7 +12,7 @@ License: GPL-3
1212
Encoding: UTF-8
1313
Language: en-US
1414
Depends:
15-
R (>= 3.4.0)
15+
R (>= 3.5.0)
1616
Imports:
1717
magrittr,
1818
dplyr,
@@ -36,7 +36,7 @@ Suggests:
3636
ggiraph,
3737
testthat (>= 3.0.0)
3838
URL: https://michalovadek.github.io/eurlex/
39-
RoxygenNote: 7.2.3
39+
RoxygenNote: 7.3.1
4040
Roxygen: list(markdown = TRUE)
4141
VignetteBuilder: knitr
4242
Config/testthat/edition: 3

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# eurlex 0.4.7
2+
3+
## Minor changes
4+
- some http calls were still not failing gracefully
5+
- some leftover .data in tidyselect
6+
17
# eurlex 0.4.6
28

39
## Minor changes

R/elx_curia_list.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ elx_curia_list <- function(data = c("all","ecj_old","ecj_new","gc_all","cst_all"
3333

3434
else {data <- match.arg(data)}
3535

36-
3736
if (data == "all"){
3837

3938
res_c1 <- elx_curia_scraper(url_c1)
@@ -89,7 +88,6 @@ elx_curia_list <- function(data = c("all","ecj_old","ecj_new","gc_all","cst_all"
8988

9089
}
9190

92-
9391
}
9492

9593
#' Curia scraper function
@@ -118,16 +116,16 @@ elx_curia_scraper <- function(url, ...){
118116
dplyr::mutate(dplyr::across(.cols = dplyr::everything(),
119117
.fns = ~dplyr::na_if(., ""))) %>%
120118
dplyr::filter(!is.na(.data$X1) & !is.na(.data$X2)) %>%
121-
dplyr::rename(case_id = .data$X1,
122-
case_info = .data$X2) %>%
119+
dplyr::rename(case_id = "X1",
120+
case_info = "X2") %>%
123121
dplyr::group_by(.data$case_id) %>%
124122
dplyr::mutate(n_id = dplyr::row_number()) %>%
125123
dplyr::ungroup()
126124

127125
hrefs <- page %>%
128126
xml2::xml_find_all('//a[contains(@href, "numdoc")]')
129127

130-
linked_id <- rvest::html_text(hrefs, "href")
128+
linked_id <- rvest::html_text(hrefs, trim = TRUE)
131129

132130
linked_celex <- rvest::html_attr(hrefs, "href") %>%
133131
stringr::str_extract("numdoc=.*") %>%
@@ -141,7 +139,7 @@ elx_curia_scraper <- function(url, ...){
141139

142140
out <- dplyr::left_join(tab, linked, by = c("case_id"="linked_id","n_id"="n_id")) %>%
143141
dplyr::select("case_id", "linked_celex", "case_info") %>%
144-
dplyr::rename(case_id_celex = linked_celex)
142+
dplyr::rename(case_id_celex = "linked_celex")
145143

146144
return(out)
147145

R/elx_run_query.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ graceful_http <- function(remote_file, headers = NULL, body = NULL,
5959
return(invisible(NULL))
6060
}
6161

62+
# if missing verb pick GET
63+
if (missing(verb)){
64+
verb <- "GET"
65+
}
66+
6267
# Make the HTTP request based on the verb
6368
make_request <- function(verb) {
6469
tryCatch({
@@ -72,25 +77,21 @@ graceful_http <- function(remote_file, headers = NULL, body = NULL,
7277
}
7378
},
7479
error = function(e) {
75-
message("Error: ", conditionMessage(e))
80+
message(conditionMessage(e), " (Error)")
7681
return(invisible(NULL))
7782
},
7883
warning = function(w) {
79-
message("Warning: ", conditionMessage(w))
84+
message(conditionMessage(w), " (Warning)")
8085
return(invisible(NULL))
8186
})
8287
}
8388

8489
# Execute the request
8590
resp <- make_request(verb)
8691

87-
# Check for HTTP errors
88-
if (httr::http_error(resp)) {
89-
httr::message_for_status(resp)
90-
return(invisible(NULL))
91-
}
92-
92+
# return
9393
return(resp)
94+
9495
}
9596

9697
#' Parse RDF/XML triplets to data frame

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/council.html

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
HTMLWidgets.widget({
2+
name: 'girafe',
3+
type: 'output',
4+
factory: ggiraphjs.factory(HTMLWidgets.shinyMode)
5+
});

0 commit comments

Comments
 (0)