2222 * Utility class for making HTTP requests
2323 */
2424public class HttpUtility {
25+ public static final boolean DEBUG = false ;
26+
2527 /**
2628 * Sends a GET request to the specified URL and returns the result of the specified function
2729 *
@@ -43,10 +45,13 @@ public static <T> Optional<T> get(@NotNull String userAgent, @NotNull String url
4345 connection .setRequestMethod ("GET" );
4446 connection .setRequestProperty ("User-Agent" , userAgent );
4547 if (connectionConsumer != null ) connectionConsumer .accept (connection );
46- if (connection .getResponseCode () == 404 ) return Optional .empty ();
48+ if (connection .getResponseCode () == 404 ) {
49+ if (DEBUG ) System .out .println ("[JU] 404: " + url );
50+ return Optional .empty ();
51+ }
4752 result = function .apply (new InputStreamReader (connection .getInputStream ()));
48- } catch (final IOException ignored ) {
49- // Ignored
53+ } catch (final IOException e ) {
54+ if ( DEBUG ) e . printStackTrace ();
5055 }
5156 if (connection != null ) connection .disconnect ();
5257 return Optional .ofNullable (result );
@@ -102,8 +107,8 @@ public static int postJson(@NotNull String userAgent, @NotNull String urlString,
102107 if (connectionConsumer != null ) connectionConsumer .accept (connection );
103108 connection .getOutputStream ().write (data .toString ().getBytes ());
104109 responseCode = connection .getResponseCode ();
105- } catch (final IOException ignored ) {
106- // Ignored
110+ } catch (final IOException e ) {
111+ if ( DEBUG ) e . printStackTrace ();
107112 }
108113 if (connection != null ) connection .disconnect ();
109114 return responseCode ;
@@ -131,8 +136,8 @@ public static int putJson(@NotNull String userAgent, @NotNull String urlString,
131136 if (connectionConsumer != null ) connectionConsumer .accept (connection );
132137 connection .getOutputStream ().write (data .toString ().getBytes ());
133138 responseCode = connection .getResponseCode ();
134- } catch (final IOException ignored ) {
135- // Ignored
139+ } catch (final IOException e ) {
140+ if ( DEBUG ) e . printStackTrace ();
136141 }
137142 if (connection != null ) connection .disconnect ();
138143 return responseCode ;
@@ -160,8 +165,8 @@ public static int patchJson(@NotNull String userAgent, @NotNull String urlString
160165 if (connectionConsumer != null ) connectionConsumer .accept (connection );
161166 connection .getOutputStream ().write (data .toString ().getBytes ());
162167 responseCode = connection .getResponseCode ();
163- } catch (final IOException ignored ) {
164- // Ignored
168+ } catch (final IOException e ) {
169+ if ( DEBUG ) e . printStackTrace ();
165170 }
166171 if (connection != null ) connection .disconnect ();
167172 return responseCode ;
@@ -185,8 +190,8 @@ public static int delete(@NotNull String userAgent, @NotNull String urlString, @
185190 connection .setRequestProperty ("User-Agent" , userAgent );
186191 if (connectionConsumer != null ) connectionConsumer .accept (connection );
187192 responseCode = connection .getResponseCode ();
188- } catch (final IOException ignored ) {
189- // Ignored
193+ } catch (final IOException e ) {
194+ if ( DEBUG ) e . printStackTrace ();
190195 }
191196 if (connection != null ) connection .disconnect ();
192197 return responseCode ;
0 commit comments