Handling gracefully any errors
parent
0a078f1321
commit
e7e1ee81e4
|
@ -46,6 +46,8 @@ public class GooglePlacesWorker extends AsyncTask<GooglePlacesRequest, Integer,
|
||||||
Location location = param.getLocation();
|
Location location = param.getLocation();
|
||||||
|
|
||||||
Response<GooglePlaceResponse> placesResponse = null;
|
Response<GooglePlaceResponse> placesResponse = null;
|
||||||
|
GooglePlacesResponse response = new GooglePlacesResponse();
|
||||||
|
response.setOriginalPageToken(param.getPageToken());
|
||||||
try {
|
try {
|
||||||
placesResponse = placesUtils.fetchNearbyPlaces(
|
placesResponse = placesUtils.fetchNearbyPlaces(
|
||||||
location.getLatitude(),
|
location.getLatitude(),
|
||||||
|
@ -62,18 +64,23 @@ public class GooglePlacesWorker extends AsyncTask<GooglePlacesRequest, Integer,
|
||||||
placesResponse.body(),
|
placesResponse.body(),
|
||||||
placesResponse.errorBody(),
|
placesResponse.errorBody(),
|
||||||
placesResponse.message());
|
placesResponse.message());
|
||||||
GooglePlacesResponse response = new GooglePlacesResponse();
|
|
||||||
final GooglePlaceResponse responseBody = placesResponse.body();
|
final GooglePlaceResponse responseBody = placesResponse.body();
|
||||||
lg.debug("Google response body: {}", responseBody);
|
lg.debug("Google response body: {}", responseBody);
|
||||||
response.setPlaces(responseBody.getResults());
|
response.setPlaces(responseBody.getResults());
|
||||||
response.setNextPageToken(responseBody.getNextPageToken());
|
response.setNextPageToken(responseBody.getNextPageToken());
|
||||||
response.setOriginalPageToken(param.getPageToken());
|
|
||||||
response.setStatus(responseBody.getStatus());
|
response.setStatus(responseBody.getStatus());
|
||||||
result.add(response);
|
result.add(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
lg.error("I/O error", e);
|
lg.error("I/O error", e);
|
||||||
|
response.setStatus("I/O error: " + e.getMessage());
|
||||||
|
result.add(response);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
lg.error("General error", t);
|
||||||
|
response.setStatus("General error: " + t.getMessage());
|
||||||
|
result.add(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue