Skip to content

Commit

Permalink
fix #298 better failure behavior for swdi fxns during govt shutdown, …
Browse files Browse the repository at this point in the history
…bump vers
  • Loading branch information
sckott committed Jan 9, 2019
1 parent bc75a93 commit 92d0f1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions R/swdi.r
Original file line number Diff line number Diff line change
Expand Up @@ -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(...))
Expand Down
7 changes: 7 additions & 0 deletions R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ",")
Expand Down

0 comments on commit 92d0f1d

Please sign in to comment.