diff --git a/openbas-framework/src/main/java/io/openbas/executors/tanium/client/TaniumExecutorClient.java b/openbas-framework/src/main/java/io/openbas/executors/tanium/client/TaniumExecutorClient.java index dc6e20a8e4..97a027f6ee 100644 --- a/openbas-framework/src/main/java/io/openbas/executors/tanium/client/TaniumExecutorClient.java +++ b/openbas-framework/src/main/java/io/openbas/executors/tanium/client/TaniumExecutorClient.java @@ -1,5 +1,6 @@ package io.openbas.executors.tanium.client; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import io.openbas.executors.tanium.config.TaniumExecutorConfig; @@ -8,7 +9,9 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; import lombok.RequiredArgsConstructor; +import lombok.extern.java.Log; import org.apache.hc.client5.http.ClientProtocolException; import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; @@ -19,6 +22,7 @@ @RequiredArgsConstructor @Service +@Log public class TaniumExecutorClient { private static final String KEY_HEADER = "session"; @@ -52,8 +56,19 @@ public DataEndpoints endpoints() { Map body = new HashMap<>(); body.put("query", query); String jsonResponse = this.post(body); + if (jsonResponse == null || jsonResponse.isEmpty()) { + log.log(Level.SEVERE, "Received empty response from API for query: {}", query); + throw new RuntimeException("API returned an empty response"); + } return this.objectMapper.readValue(jsonResponse, new TypeReference<>() {}); + } catch (JsonProcessingException e) { + log.log(Level.SEVERE, "Failed to parse JSON response. Error: {}", e.getMessage()); + throw new RuntimeException(e); } catch (IOException e) { + log.log(Level.SEVERE, "I/O error occurred during API request. Error: {}", e.getMessage()); + throw new RuntimeException(e); + } catch (Exception e) { + log.log(Level.SEVERE, "Unexpected error occurred. Error: {}", e.getMessage()); throw new RuntimeException(e); } }