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
#' @return \code{TRUE} if the API is available, otherwise \code{stop()} is called.
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)
}

Try the fingertipscharts package in your browser

Any scripts or data that you put into this service are public.

fingertipscharts documentation built on July 2, 2020, 2:59 a.m.