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 401b866..83d93c2 100644 --- a/src/main/java/ru/soune/nocopy/service/search/SearchImageService.java +++ b/src/main/java/ru/soune/nocopy/service/search/SearchImageService.java @@ -114,7 +114,12 @@ public class SearchImageService { } private String callReverseImageApiByUrl(String imageUrl, String engine, String searchType) throws IOException { + log.info("=== START SEARCH API CALL ==="); + log.info("Engine: {}, SearchType: {}", engine, searchType); + log.info("ImageUrl: {}", imageUrl); + if (searchApiKey == null || searchApiKey.isBlank()) { + log.error("SearchAPI key not configured"); throw new IllegalStateException("SearchAPI key not configured"); } @@ -129,6 +134,8 @@ public class SearchImageService { .addQueryParameter("t_", String.valueOf(System.currentTimeMillis())) .build(); + log.info("Request URL: {}", url); + Request request = new Request.Builder() .url(url) .header("Accept", "application/json") @@ -144,20 +151,25 @@ public class SearchImageService { ResponseBody body = response.body(); if (body == null) { + log.error("Response body is null"); throw new IOException("Empty response body"); } String responseBody = body.string(); - log.info("responseBody: " + responseBody); - log.info("responseBody: " + responseBody); - log.info("responseBody: " + responseBody); + log.info("=== RESPONSE BODY LENGTH: {} ===", responseBody.length()); + log.info("=== RESPONSE BODY START: {} ===", + responseBody.length() > 200 ? responseBody.substring(0, 200) : responseBody); if (!response.isSuccessful()) { + log.error("Response not successful: {}", response.code()); throw new IOException("API error " + response.code() + ": " + responseBody); } return responseBody; + } catch (Exception e) { + log.error("Exception in search API call: {}", e.getMessage(), e); + throw e; } }