Skip to content

Commit ad8e67f

Browse files
committed
Update ConnectionUtils.java
1 parent fb97b75 commit ad8e67f

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

src/main/java/io/github/intisy/utils/utils/ConnectionUtils.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.JsonObject;
44
import com.google.gson.JsonParser;
5+
import com.google.gson.Strictness;
56
import com.google.gson.stream.JsonReader;
67
import io.github.intisy.simple.logger.Log;
78

@@ -143,22 +144,18 @@ public static JsonObject handleResponse(HttpURLConnection connection) throws IOE
143144
}
144145
String response = read(br);
145146
JsonReader reader = new JsonReader(new StringReader(response));
146-
reader.setLenient(true);
147+
reader.setStrictness(Strictness.LENIENT);
148+
JsonObject jsonObject;
147149
try {
148-
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
149-
if (responseCode != HttpURLConnection.HTTP_OK) {
150-
Log.warning(jsonObject.toString());
151-
if (jsonObject.get("message").getAsString().equals("Invalid key parameter")) {
152-
Log.error("Invalid API key found.");
153-
//TODO rework login
154-
}
155-
}
156-
br.close();
157-
return jsonObject;
150+
jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
158151
} catch (Exception e) {
159-
System.err.println("Failed to parse JSON: " + e.getMessage());
160-
return new JsonObject();
152+
throw new IOException("Failed to parse JSON: " + e.getMessage());
161153
}
154+
if (responseCode != HttpURLConnection.HTTP_OK) {
155+
throw new IOException("Response code: " + responseCode + " response: " + jsonObject.toString());
156+
}
157+
br.close();
158+
return jsonObject;
162159
}
163160

164161
public static String read(BufferedReader br) throws IOException {

0 commit comments

Comments
 (0)