Skip to content

Commit

Permalink
- Update API Tester
Browse files Browse the repository at this point in the history
  • Loading branch information
haideriqbal committed Sep 10, 2024
1 parent bc40c53 commit 4df986a
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,15 @@ public static JsonElement get(String url) throws IOException {
System.out.println("GET " + url);

HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
InputStream is = null;

if (100 <= conn.getResponseCode() && conn.getResponseCode() <= 399) {
InputStream is = conn.getInputStream();
Reader reader = new InputStreamReader(is, "UTF-8");
JsonElement result = JsonParser.parseReader(reader);
return result;
is = conn.getInputStream();
} else {
InputStream is = conn.getErrorStream();
Reader reader = new InputStreamReader(is, "UTF-8");
JsonObject error = new JsonObject();
error.addProperty("error", IOUtils.toString(is, StandardCharsets.UTF_8));
return error;
is = conn.getErrorStream();
}
Reader reader = new InputStreamReader(is, "UTF-8");
return JsonParser.parseReader(reader);
}

public JsonElement normalizeURLs(JsonElement element) {
Expand Down

0 comments on commit 4df986a

Please sign in to comment.