@@ -115,17 +115,23 @@ private JSONObject performGET(@NotNull String url) throws IOException, Ratelimit
115115 }
116116 }
117117
118- void performPOST (@ NotNull JSONObject json ) throws IOException , RatelimitedException {
118+ void performPOST (@ NotNull JSONObject json , int sites ) throws IOException , RatelimitedException {
119119 String url = BASE_URL + "count" ;
120120
121+ OkHttpClient postClient = CLIENT .newBuilder ()
122+ .callTimeout (sites *10 , TimeUnit .SECONDS )
123+ .readTimeout (sites *10 , TimeUnit .SECONDS )
124+ .writeTimeout (sites *10 , TimeUnit .SECONDS )
125+ .build ();
126+
121127 RequestBody body = RequestBody .create (json .toString (), null );
122128 Request request = new Request .Builder ()
123129 .url (url )
124130 .addHeader ("Content-Type" , "application/json" )
125131 .post (body )
126132 .build ();
127133
128- try (Response response = CLIENT .newCall (request ).execute ()){
134+ try (Response response = postClient .newCall (request ).execute ()){
129135 ResponseBody responseBody = response .body ();
130136 if (responseBody == null )
131137 throw new NullPointerException ("Received empty response body." );
@@ -148,25 +154,25 @@ void performPOST(@NotNull JSONObject json) throws IOException, RatelimitedExcept
148154 if (responseJson .has ("failure" )){
149155 JSONObject failure = responseJson .getJSONObject ("failure" );
150156
151- List <String > sites = new ArrayList <>();
157+ List <String > failedSites = new ArrayList <>();
152158 for (String key : failure .keySet ()){
153159 try {
154160 JSONArray array = failure .getJSONArray (key );
155- sites .add (String .format (
161+ failedSites .add (String .format (
156162 "Site: %s, Code: %d, Message: %s" ,
157163 key ,
158164 array .getInt (0 ),
159165 array .getString (1 )
160166 ));
161167 }catch (JSONException ex ){
162168 Map <String , Object > notFound = failure .toMap ();
163- sites .add ("Errors: " + notFound .toString ());
169+ failedSites .add ("Errors: " + notFound .toString ());
164170 }
165171 }
166172
167173 throw new IOException (String .format (
168174 "One or multiple post requests failed! Response(s): %s" ,
169- String .join (", " , sites )
175+ String .join (", " , failedSites )
170176 ));
171177 }
172178 }
0 commit comments