File tree Expand file tree Collapse file tree
src/main/java/io/github/intisy/utils/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import com .google .gson .JsonObject ;
44import com .google .gson .JsonParser ;
5+ import com .google .gson .Strictness ;
56import com .google .gson .stream .JsonReader ;
67import 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 {
You can’t perform that action at this time.
0 commit comments