Skip to content
Browse files

Handle some errors

  • Loading branch information...
1 parent 7d03fa8 commit 072e7f1ddbef0d0051b87ed9bb8e3a2eb6491782 @trajano committed Feb 10, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/main/java/net/trajano/gasprices/GasPricesUpdateService.java
View
9 src/main/java/net/trajano/gasprices/GasPricesUpdateService.java
@@ -87,10 +87,15 @@ private JSONObject getGasPricesDataFromInternet() throws IOException {
final String jsonData = new Scanner(urlConnection.getInputStream())
.useDelimiter("\\A").next().substring(1);
- return (JSONObject) new JSONTokener(jsonData).nextValue();
+ final Object value = new JSONTokener(jsonData).nextValue();
+ if (value instanceof JSONObject) {
+ return (JSONObject) value;
+ } else {
+ throw new IOException("Did not get a proper JSON object");
+ }
} catch (final JSONException e) {
Log.e("GasPrices", e.getMessage());
- return null;
+ throw new IOException(e);
} finally {
urlConnection.disconnect();
}

0 comments on commit 072e7f1

Please sign in to comment.
Something went wrong with that request. Please try again.