|
22 | 22 | import com.graphhopper.api.model.GHGeocodingResponse;
|
23 | 23 | import okhttp3.OkHttpClient;
|
24 | 24 | import okhttp3.Request;
|
| 25 | +import okhttp3.Response; |
25 | 26 | import okhttp3.ResponseBody;
|
26 | 27 |
|
| 28 | +import java.io.IOException; |
27 | 29 | import java.io.UnsupportedEncodingException;
|
28 | 30 | import java.net.URLEncoder;
|
29 | 31 | import java.util.concurrent.TimeUnit;
|
@@ -73,13 +75,16 @@ public GraphHopperGeocoding(String serviceUrl) {
|
73 | 75 | */
|
74 | 76 | public GHGeocodingResponse geocode(GHGeocodingRequest request) {
|
75 | 77 | String url = buildUrl(request);
|
76 |
| - |
77 | 78 | try {
|
78 | 79 | Request okRequest = new Request.Builder().url(url).build();
|
79 |
| - ResponseBody rspBody = getClientForRequest(request).newCall(okRequest).execute().body(); |
80 |
| - return objectMapper.readValue(rspBody.bytes(), GHGeocodingResponse.class); |
81 |
| - } catch (Exception ex) { |
82 |
| - throw new RuntimeException("Problem performing geocoding for " + url + ": " + ex.getMessage(), ex); |
| 80 | + Response rsp = getClientForRequest(request).newCall(okRequest).execute(); |
| 81 | + ResponseBody rspBody = rsp.body(); |
| 82 | + if (!rsp.isSuccessful()) |
| 83 | + throw new RuntimeException(rspBody.string()); |
| 84 | + GHGeocodingResponse geoRsp = objectMapper.readValue(rspBody.bytes(), GHGeocodingResponse.class); |
| 85 | + return geoRsp; |
| 86 | + } catch (IOException ex) { |
| 87 | + throw new RuntimeException("IO problem for geocoding URL " + url + ": " + ex.getMessage(), ex); |
83 | 88 | }
|
84 | 89 | }
|
85 | 90 |
|
|
0 commit comments