Skip to content

Commit 1f16171

Browse files
committed
SDA_query: handle no content-type header
- i.e. during "Site is under daily maintenance from 12:30 AM CST to 12:45 AM CST. Please try after 12:45 AM CST."
1 parent 02b52fd commit 1f16171

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

R/SDA_query.R

+14-4
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,22 @@ SDA_query <- function(q, dsn = NULL) {
166166

167167
# check response content type
168168
h <- r$all_headers
169+
169170
if (!is.null(h)) {
170-
if (length(h) == 0 || !h[[1]]$headers$`content-type` %in%
171+
if (length(h) == 0
172+
|| is.null(h[[1]]$headers$`content-type`)
173+
|| !h[[1]]$headers$`content-type` %in%
171174
c("application/json; charset=utf-8", # data response
172-
"text/xml; charset=utf-8") # error response
173-
) {
174-
r <- try(stop("Soil Data Access POST REST API is not currently available, please try again later.", call. = FALSE), silent = TRUE)
175+
"text/xml; charset=utf-8") # error response (maybe not anymore?)
176+
) {
177+
msg <- "Soil Data Access REST API is not currently available, please try again later."
178+
if (is.null(h[[1]]$headers$`content-type`))
179+
txt <- try(httr::content(r, as = "text", encoding = "UTF-8"), silent = TRUE)
180+
if (!inherits(txt, 'try-error')) {
181+
msg <- gsub("<[^>]*>", "", txt)
182+
}
183+
}
184+
r <- try(stop(msg, call. = FALSE), silent = TRUE)
175185
}
176186
}
177187

0 commit comments

Comments
 (0)