diff --git a/src/main/java/com/google/genai/errors/ApiException.java b/src/main/java/com/google/genai/errors/ApiException.java index 0d8fa31f77f..5d8c95dec15 100644 --- a/src/main/java/com/google/genai/errors/ApiException.java +++ b/src/main/java/com/google/genai/errors/ApiException.java @@ -25,11 +25,6 @@ import java.io.IOException; import okhttp3.Response; import okhttp3.ResponseBody; -import org.apache.http.HttpEntity; -import org.apache.http.HttpStatus; -import org.apache.http.StatusLine; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.util.EntityUtils; /** General exception class for all exceptions originating from the GenAI API side. */ public class ApiException extends BaseException { @@ -52,31 +47,6 @@ public ApiException(int code, String status, String message) { this.message = message; } - /** - * Throws an ApiException from the response if the response is not a OK status. - * - * @param response The response from the API call. - * @deprecated Use {@link #throwFromResponse(Response)} instead. - */ - @ExcludeFromGeneratedCoverageReport - @Deprecated - public static void throwFromResponse(CloseableHttpResponse response) { - StatusLine statusLine = response.getStatusLine(); - int code = statusLine.getStatusCode(); - if (code == HttpStatus.SC_OK) { - return; - } - String status = statusLine.getReasonPhrase(); - String message = getErrorMessageFromResponse(response); - if (code >= 400 && code < 500) { // Client errors. - throw new ClientException(code, status, message); - } else if (code >= 500 && code < 600) { // Server errors. - throw new ServerException(code, status, message); - } else { - throw new ApiException(code, status, message); - } - } - /** * Throws an ApiException from the response if the response is not a OK status. * @@ -99,33 +69,6 @@ public static void throwFromResponse(Response response) { } } - /** - * Returns the error message from the response, if no error or error message is not found, then - * returns an empty string. - */ - @ExcludeFromGeneratedCoverageReport - @Deprecated - static String getErrorMessageFromResponse(CloseableHttpResponse response) { - HttpEntity entity = response.getEntity(); - try { - String responseBody = EntityUtils.toString(entity); - if (responseBody == null || responseBody.isEmpty()) { - return ""; - } - ObjectMapper mapper = new ObjectMapper(); - JsonNode errorNode = mapper.readTree(responseBody).get("error"); - if (errorNode != null && errorNode.isObject()) { - JsonNode messageNode = errorNode.get("message"); - if (messageNode != null && messageNode.isTextual()) { - return messageNode.asText(); - } - } - return ""; - } catch (IOException ignored) { - return ""; - } - } - /** * Returns the error message from the response, if no error or error message is not found, then * returns an empty string.