diff --git a/.DS_Store b/.DS_Store index 5235de3..8499cec 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/R/.DS_Store b/R/.DS_Store index fddade1..f88b589 100644 Binary files a/R/.DS_Store and b/R/.DS_Store differ diff --git a/R/getMasterlist.R b/R/getMasterlist.R index 4938fd1..9715fdc 100644 --- a/R/getMasterlist.R +++ b/R/getMasterlist.R @@ -34,18 +34,36 @@ getMasterList <- function(session = NULL, state = NULL, legiKey = NULL){ } } - req <- httr2::request( - "https://api.legiscan.com" - ) |> - httr2::req_url_query( - key = legiKey, - op = op, - state = state, - id = session, - .multi = "explode" + tryCatch({ + req <- httr2::request( + "https://api.legiscan.com" ) |> - httr2::req_perform() |> - httr2::resp_body_json() - print(req$masterlist$session$session_name) - return(dplyr::bind_rows(req$masterlist[-1])) + httr2::req_url_query( + key = legiKey, + op = op, + state = state, + id = session, + .multi = "explode" + ) |> + httr2::req_perform() + + status <- httr2::resp_status(req) + if (status != 200) { + stop(sprintf("API request failed with status code: %d", status)) + } + + response <- httr2::resp_body_json(req) + + if (!is.null(response$status)) { + if (response$status != "OK") { + stop(sprintf("API returned error: %s", response$alert)) + } + } + + print(response$masterlist$session$session_name) + return(dplyr::bind_rows(response$masterlist[-1])) + + }, error = function(e) { + stop(sprintf("Error in API request: %s", e$message)) + }) } diff --git a/R/getSessions.R b/R/getSessions.R index 75ecf89..1206a06 100644 --- a/R/getSessions.R +++ b/R/getSessions.R @@ -13,7 +13,7 @@ #' getSessions(state = "MA") #' #' @export -getSessions <- function(state = "TX", legiKey = NULL){ +getSessions <- function(state = NULL, legiKey = NULL){ op <- "getSessionlist" if (is.null(legiKey)){