diff --git a/src/main/java/ru/soune/nocopy/service/search/SearchImageService.java b/src/main/java/ru/soune/nocopy/service/search/SearchImageService.java index 8e5e4b4..e896d8a 100644 --- a/src/main/java/ru/soune/nocopy/service/search/SearchImageService.java +++ b/src/main/java/ru/soune/nocopy/service/search/SearchImageService.java @@ -141,17 +141,18 @@ public class SearchImageService { log.info("SearchAPI response code={}, duration={}ms, engine={}", response.code(), duration, engine); - if (!response.isSuccessful()) { - String errorBody = response.body() != null ? response.body().string() : "null"; - throw new IOException("API error " + response.code() + ": " + errorBody); - } - ResponseBody body = response.body(); if (body == null) { throw new IOException("Empty response body"); } - return body.string(); + String responseBody = body.string(); + + if (!response.isSuccessful()) { + throw new IOException("API error " + response.code() + ": " + responseBody); + } + + return responseBody; } }