@@ -140,7 +140,6 @@ private String callApi(String url) throws IOException {
140140 if (httpClient == null ) {
141141 throw new IllegalStateException ("ServerConnection must be initialized" );
142142 }
143- LOG .debug ("Call API: {}}" , url );
144143 try (ResponseBody responseBody = callUrl (url , true , null )) {
145144 return responseBody .string ();
146145 }
@@ -152,31 +151,30 @@ private String callApi(String url) throws IOException {
152151 * @param url the URL to call
153152 * @param authentication if true, the request will be authenticated with the token
154153 * @param acceptHeader the value of the Accept header
155- * @throws IOException if connectivity error/timeout (network)
156154 * @throws IllegalStateException if HTTP code is different than 2xx
157155 */
158- private ResponseBody callUrl (String url , boolean authentication , @ Nullable String acceptHeader ) throws IOException {
156+ private ResponseBody callUrl (String url , boolean authentication , @ Nullable String acceptHeader ) {
157+ var requestBuilder = new Request .Builder ()
158+ .get ()
159+ .url (url )
160+ .addHeader ("User-Agent" , userAgent );
161+ if (authentication && credentials != null ) {
162+ requestBuilder .header ("Authorization" , credentials );
163+ }
164+ if (acceptHeader != null ) {
165+ requestBuilder .header ("Accept" , acceptHeader );
166+ }
167+ Request request = requestBuilder .build ();
168+ Response response ;
159169 try {
160- var requestBuilder = new Request .Builder ()
161- .get ()
162- .url (url )
163- .addHeader ("User-Agent" , userAgent );
164- if (authentication && credentials != null ) {
165- requestBuilder .header ("Authorization" , credentials );
166- }
167- if (acceptHeader != null ) {
168- requestBuilder .header ("Accept" , acceptHeader );
169- }
170- Request request = requestBuilder .build ();
171- Response response = httpClient .newCall (request ).execute ();
172- if (!response .isSuccessful ()) {
173- response .close ();
174- throw new IllegalStateException (format ("Error status returned by url [%s]: %s" , response .request ().url (), response .code ()));
175- }
176- return response .body ();
170+ response = httpClient .newCall (request ).execute ();
177171 } catch (Exception e ) {
178- LOG .error ("Call to URL [{}] failed" , url );
179- throw e ;
172+ throw new IllegalStateException (format ("Call to URL [%s] failed" , url ), e );
173+ }
174+ if (!response .isSuccessful ()) {
175+ response .close ();
176+ throw new IllegalStateException (format ("Error status returned by url [%s]: %s" , response .request ().url (), response .code ()));
180177 }
178+ return response .body ();
181179 }
182180}
0 commit comments