Skip to content
Snippets Groups Projects
Commit 79d44b88 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Added error handling

parent 58cad19b
No related branches found
No related tags found
1 merge request!9Added a lot of error handling.
...@@ -24,8 +24,16 @@ ...@@ -24,8 +24,16 @@
#' unitData <- getWaterML1Data(unitDataURL) #' unitData <- getWaterML1Data(unitDataURL)
getWaterML1Data <- function(obs_url){ getWaterML1Data <- function(obs_url){
h <- basicHeaderGatherer()
doc = tryCatch({ doc = tryCatch({
doc <- xmlTreeParse(obs_url, getDTD = FALSE, useInternalNodes = TRUE) returnedDoc <- getURI(obs_url, headerfunction = h$update)
if(h$value()["Content-Type"] == "text/xml;charset=UTF-8"){
xmlTreeParse(returnedDoc, getDTD = FALSE, useInternalNodes = TRUE)
} else {
message(paste("URL caused an error:", obs_url))
message("Content-Type=",h$value()["Content-Type"])
return(NA)
}
}, warning = function(w) { }, warning = function(w) {
message(paste("URL caused a warning:", obs_url)) message(paste("URL caused a warning:", obs_url))
...@@ -36,6 +44,7 @@ getWaterML1Data <- function(obs_url){ ...@@ -36,6 +44,7 @@ getWaterML1Data <- function(obs_url){
return(NA) return(NA)
}) })
doc <- xmlRoot(doc) doc <- xmlRoot(doc)
ns <- xmlNamespaceDefinitions(doc, simplify = TRUE) ns <- xmlNamespaceDefinitions(doc, simplify = TRUE)
timeSeries <- xpathApply(doc, "//ns1:timeSeries", namespaces = ns) timeSeries <- xpathApply(doc, "//ns1:timeSeries", namespaces = ns)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment