Skip to content

Commit 796853f

Browse files
committed
Update wiDB funcs
1 parent 9bff63d commit 796853f

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

CRAN-RELEASE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This package was submitted to CRAN on 2021-06-10.
2-
Once it is accepted, delete this file and tag the release (commit 9d5e104).
1+
This package was submitted to CRAN on 2021-07-14.
2+
Once it is accepted, delete this file and tag the release (commit 9bff63d).

R/wiDBfunctions.R

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,25 @@ wiDB_sites = function(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NU
101101
baseStr = "https://wateriso.utah.edu/api/v1/sites.php"
102102
q = paste0(baseStr, qStr)
103103
ua = user_agent("https://github.com/SPATIAL-Lab/isoWater")
104-
d = GET(q, ua)
104+
d = tryCatch({
105+
GET(q, ua)
106+
},
107+
error = function(x){
108+
message(conditionMessage(x))
109+
return(NULL)
110+
},
111+
warning = function(x){
112+
message(conditionMessage(x))
113+
return(NULL)
114+
}
115+
)
116+
117+
if(is.null(d)){return()}
105118

106-
if(d$status_code != 200){stop(paste("Request returned error code", d$status_code))}
119+
if(d$status_code != 200){
120+
message(paste("Request returned error code", d$status_code))
121+
return(NULL)
122+
}
107123

108124
resp = fromJSON(content(d, as = "text", encoding = "UTF-8"))
109125

@@ -156,9 +172,26 @@ wiDB_data = function(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NUL
156172
baseStr = "https://wateriso.utah.edu/api/v1/download.php"
157173
q = paste0(baseStr, qStr)
158174
ua = user_agent("https://github.com/SPATIAL-Lab/isoWater")
159-
g = GET(q, ua)
175+
176+
g = tryCatch({
177+
GET(q, ua)
178+
},
179+
error = function(x){
180+
message(conditionMessage(x))
181+
return(NULL)
182+
},
183+
warning = function(x){
184+
message(conditionMessage(x))
185+
return(NULL)
186+
}
187+
)
160188

161-
if(g$status_code != 200){stop(paste("Request returned error code", g$status_code))}
189+
if(is.null(g)){return()}
190+
191+
if(g$status_code != 200){
192+
message(paste("Request returned error code", d$status_code))
193+
return(NULL)
194+
}
162195

163196
fn = g$headers$`content-disposition`
164197
fn = strsplit(fn, "=")[[1]][2]
@@ -216,9 +249,26 @@ wiDB_values = function(fields){
216249
}
217250
q = substr(q, 1, nchar(q) - 1)
218251
ua = user_agent("https://github.com/SPATIAL-Lab/isoWater")
219-
d = GET(q, ua)
252+
253+
d = tryCatch({
254+
GET(q, ua)
255+
},
256+
error = function(x){
257+
message(conditionMessage(x))
258+
return(NULL)
259+
},
260+
warning = function(x){
261+
message(conditionMessage(x))
262+
return(NULL)
263+
}
264+
)
265+
266+
if(is.null(d)){return()}
220267

221-
if(d$status_code != 200){stop(paste("Request returned error code", d$status_code))}
268+
if(d$status_code != 200){
269+
message(paste("Request returned error code", d$status_code))
270+
return(NULL)
271+
}
222272

223273
resp = fromJSON(content(d, as = "text", encoding = "UTF-8"))
224274

0 commit comments

Comments
 (0)