Skip to content

Commit

Permalink
047 handling http failures
Browse files Browse the repository at this point in the history
  • Loading branch information
michalovadek committed Feb 25, 2024
1 parent 225684d commit dffc72b
Show file tree
Hide file tree
Showing 28 changed files with 988 additions and 70 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: eurlex
Type: Package
Title: Retrieve Data on European Union Law
Version: 0.4.6
Version: 0.4.7
Authors@R: c(person(given = "Michal",
family = "Ovadek",
role = c("aut", "cre", "cph"),
Expand All @@ -12,7 +12,7 @@ License: GPL-3
Encoding: UTF-8
Language: en-US
Depends:
R (>= 3.4.0)
R (>= 3.5.0)
Imports:
magrittr,
dplyr,
Expand All @@ -36,7 +36,7 @@ Suggests:
ggiraph,
testthat (>= 3.0.0)
URL: https://michalovadek.github.io/eurlex/
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Config/testthat/edition: 3
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# eurlex 0.4.7

## Minor changes
- some http calls were still not failing gracefully
- some leftover .data in tidyselect

# eurlex 0.4.6

## Minor changes
Expand Down
10 changes: 4 additions & 6 deletions R/elx_curia_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ elx_curia_list <- function(data = c("all","ecj_old","ecj_new","gc_all","cst_all"

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


if (data == "all"){

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

}


}

#' Curia scraper function
Expand Down Expand Up @@ -118,16 +116,16 @@ elx_curia_scraper <- function(url, ...){
dplyr::mutate(dplyr::across(.cols = dplyr::everything(),
.fns = ~dplyr::na_if(., ""))) %>%
dplyr::filter(!is.na(.data$X1) & !is.na(.data$X2)) %>%
dplyr::rename(case_id = .data$X1,
case_info = .data$X2) %>%
dplyr::rename(case_id = "X1",
case_info = "X2") %>%
dplyr::group_by(.data$case_id) %>%
dplyr::mutate(n_id = dplyr::row_number()) %>%
dplyr::ungroup()

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

linked_id <- rvest::html_text(hrefs, "href")
linked_id <- rvest::html_text(hrefs, trim = TRUE)

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

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

return(out)

Expand Down
17 changes: 9 additions & 8 deletions R/elx_run_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ graceful_http <- function(remote_file, headers = NULL, body = NULL,
return(invisible(NULL))
}

# if missing verb pick GET
if (missing(verb)){
verb <- "GET"
}

# Make the HTTP request based on the verb
make_request <- function(verb) {
tryCatch({
Expand All @@ -72,25 +77,21 @@ graceful_http <- function(remote_file, headers = NULL, body = NULL,
}
},
error = function(e) {
message("Error: ", conditionMessage(e))
message(conditionMessage(e), " (Error)")
return(invisible(NULL))
},
warning = function(w) {
message("Warning: ", conditionMessage(w))
message(conditionMessage(w), " (Warning)")
return(invisible(NULL))
})
}

# Execute the request
resp <- make_request(verb)

# Check for HTTP errors
if (httr::http_error(resp)) {
httr::message_for_status(resp)
return(invisible(NULL))
}

# return
return(resp)

}

#' Parse RDF/XML triplets to data frame
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions docs/articles/council.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/articles/council_files/girafe-binding-0.8.8/girafe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HTMLWidgets.widget({
name: 'girafe',
type: 'output',
factory: ggiraphjs.factory(HTMLWidgets.shinyMode)
});
Loading

0 comments on commit dffc72b

Please sign in to comment.