Geocoding fails when curl::curl_fetch_memory(url, handle = handle) fails in httr::GET()
- Dominant language
- R
- Stars
- 778
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
I was geocoding thousands of observations and in the middle of the process, it failed like this:
```r
geocoded <- geocode(subset$address)
Source : https://maps.googleapis.com/maps/api/geocode/json?address=KOMPLEK+TOMANG+ELOK+JLN.+GATOT+SUBROTO+MEDAN+Medan&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Jl.Karya+Tani+Gg+Sementara+No.8+Medan+Johor,+Medan+Dekat+dengan+Asrama...&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Geocoding "Jl.Karya Tani Gg ..." failed with error:
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Jalan+Bakti+Luhur,+Komplek+Millenium+Townhouse+1,+Dwi+Kora,+Medan+Helvetia+Medan&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Jalan+Datuk+Rubiah+Titi+Papan+Marelan+Medan+Medan&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Source : https://maps.googleapis.com/maps/api/geocode/json?address=jalan+bajak+1+,+akses+bisa+masuk+dari+sm+raja+sebelah+dinas+kehutanan+atau+akses+bisa+masuk+dari+stm+suka+iklas+alfalah+dan...&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Error in curl::curl_fetch_memory(url, handle = handle) :
Operation was aborted by an application callback
```
I think it the problem is that [this](https://github.com/dkahle/ggmap/blob/a4e1cf5cb3fa19b51ba996aaf017c313e62986df/R/geocode.R#L221) call to `httr::GET()` is not wrapped in a `tryCatch()` or similar. Then, the error message seems to come from [here](https://github.com/r-lib/httr/blob/af25ebd0e3b72d2dc6e1423242b94efc25bc97cc/R/write-function.R#L79) in the httr source code. Suggestion to fix this:
Wrap the `httr::GET()` call referenced above into `tryCatch()` (or `rlang::with_handlers()`) and return the default for the failed output with `return_failed_geocode()`. I can provide a PR if interested.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.