diff --git a/DESCRIPTION b/DESCRIPTION index 54f3ade8..9eaf6d09 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,7 @@ Description: Client for many 'NOAA' data sources including the 'NCDC' climate for 'NOAA' sea ice data, the 'NOAA' severe weather inventory, 'NOAA' Historical Observing 'Metadata' Repository ('HOMR') data, 'NOAA' storm data via 'IBTrACS', tornado data via the 'NOAA' storm prediction center, and more. -Version: 0.8.2 +Version: 0.8.2.9321 License: MIT + file LICENSE Encoding: UTF-8 Language: en-US diff --git a/R/swdi.r b/R/swdi.r index 4497392f..b67ccd1a 100644 --- a/R/swdi.r +++ b/R/swdi.r @@ -152,14 +152,16 @@ swdi <- function(dataset=NULL, format='xml', startdate=NULL, enddate=NULL, crul::url_build(base, tmp$path, tmp$parameter) } url <- make_key(url, args) + cli <- crul::HttpClient$new(url = url, opts = list(...)) + temp <- cli$get(disk = filepath) if (format == 'shp') { filepath <- paste0(filepath, ".zip") - download.file(url, destfile = filepath) - message(sprintf("Zip file downloaded to %s", filepath)) - } else if (format == 'kmz') { - download.file(url, destfile = filepath) - message(sprintf("kmz file downloaded to %s", filepath)) } + if (any(grepl("shutdown", unlist(temp$response_headers_all)))) { + on.exit(unlink(filepath), add = TRUE) + stop("there's a government shutdown; check back later") + } + message(sprintf("%s file downloaded to %s", format, filepath)) } else { if (length(args) == 0) args <- NULL cli <- crul::HttpClient$new(url = url, opts = list(...)) diff --git a/R/zzz.r b/R/zzz.r index d6c7e46a..7b2e9d19 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -129,6 +129,13 @@ check_response_swdi <- function(x, format){ warning(x$status_http()$message) } } else { + # government shutdown check + if ( + grepl("html", x$response_headers$`content-type`) && + grepl("shutdown", x$parse("UTF-8")) + ) { + stop("there's a government shutdown; check back later") + } if (format == 'csv') { stopifnot(grepl('text/plain', x$response_headers$`content-type`)) read.delim(text = x$parse("UTF-8"), sep = ",")