@@ -101,9 +101,25 @@ wiDB_sites = function(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NU
101
101
baseStr = " https://wateriso.utah.edu/api/v1/sites.php"
102
102
q = paste0(baseStr , qStr )
103
103
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 ()}
105
118
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
+ }
107
123
108
124
resp = fromJSON(content(d , as = " text" , encoding = " UTF-8" ))
109
125
@@ -156,9 +172,26 @@ wiDB_data = function(minLat = NULL, maxLat = NULL, minLong = NULL, maxLong = NUL
156
172
baseStr = " https://wateriso.utah.edu/api/v1/download.php"
157
173
q = paste0(baseStr , qStr )
158
174
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
+ )
160
188
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
+ }
162
195
163
196
fn = g $ headers $ `content-disposition`
164
197
fn = strsplit(fn , " =" )[[1 ]][2 ]
@@ -216,9 +249,26 @@ wiDB_values = function(fields){
216
249
}
217
250
q = substr(q , 1 , nchar(q ) - 1 )
218
251
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 ()}
220
267
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
+ }
222
272
223
273
resp = fromJSON(content(d , as = " text" , encoding = " UTF-8" ))
224
274
0 commit comments