R/utils.R

Defines functions ensure_ons_api_available

Documented in ensure_ons_api_available

#' Check if the given ONS json is available
#' @inheritParams map
#' @importFrom httr status_code GET
#' @return \code{TRUE} if the API is available, otherwise an error will occur.
ensure_ons_api_available <- function(ons_api) {
        code <- FALSE
        try({
                code <- httr::status_code(httr::GET(ons_api))
        }, silent = TRUE)

        if (code == 200) return(TRUE)

        errtext <- paste('The ons_api provided is currently unavailable')
        stop(errtext, call. = FALSE)
}
PublicHealthEngland/fingertipscharts documentation built on Sept. 21, 2023, 10:31 p.m.