Skip to content

Commit 081f491

Browse files
vorburgercopybara-github
authored andcommitted
fix: Remove un-used @deprecated methods in ApiException.
This is a first step towards fully removing Apache HTTP Client. See #741. FUTURE_COPYBARA_INTEGRATE_REVIEW=#799 from googleapis:release-please--branches--main 1daac4e PiperOrigin-RevId: 864281306
1 parent 8f2d67d commit 081f491

1 file changed

Lines changed: 0 additions & 57 deletions

File tree

src/main/java/com/google/genai/errors/ApiException.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
import java.io.IOException;
2626
import okhttp3.Response;
2727
import okhttp3.ResponseBody;
28-
import org.apache.http.HttpEntity;
29-
import org.apache.http.HttpStatus;
30-
import org.apache.http.StatusLine;
31-
import org.apache.http.client.methods.CloseableHttpResponse;
32-
import org.apache.http.util.EntityUtils;
3328

3429
/** General exception class for all exceptions originating from the GenAI API side. */
3530
public class ApiException extends BaseException {
@@ -52,31 +47,6 @@ public ApiException(int code, String status, String message) {
5247
this.message = message;
5348
}
5449

55-
/**
56-
* Throws an ApiException from the response if the response is not a OK status.
57-
*
58-
* @param response The response from the API call.
59-
* @deprecated Use {@link #throwFromResponse(Response)} instead.
60-
*/
61-
@ExcludeFromGeneratedCoverageReport
62-
@Deprecated
63-
public static void throwFromResponse(CloseableHttpResponse response) {
64-
StatusLine statusLine = response.getStatusLine();
65-
int code = statusLine.getStatusCode();
66-
if (code == HttpStatus.SC_OK) {
67-
return;
68-
}
69-
String status = statusLine.getReasonPhrase();
70-
String message = getErrorMessageFromResponse(response);
71-
if (code >= 400 && code < 500) { // Client errors.
72-
throw new ClientException(code, status, message);
73-
} else if (code >= 500 && code < 600) { // Server errors.
74-
throw new ServerException(code, status, message);
75-
} else {
76-
throw new ApiException(code, status, message);
77-
}
78-
}
79-
8050
/**
8151
* Throws an ApiException from the response if the response is not a OK status.
8252
*
@@ -99,33 +69,6 @@ public static void throwFromResponse(Response response) {
9969
}
10070
}
10171

102-
/**
103-
* Returns the error message from the response, if no error or error message is not found, then
104-
* returns an empty string.
105-
*/
106-
@ExcludeFromGeneratedCoverageReport
107-
@Deprecated
108-
static String getErrorMessageFromResponse(CloseableHttpResponse response) {
109-
HttpEntity entity = response.getEntity();
110-
try {
111-
String responseBody = EntityUtils.toString(entity);
112-
if (responseBody == null || responseBody.isEmpty()) {
113-
return "";
114-
}
115-
ObjectMapper mapper = new ObjectMapper();
116-
JsonNode errorNode = mapper.readTree(responseBody).get("error");
117-
if (errorNode != null && errorNode.isObject()) {
118-
JsonNode messageNode = errorNode.get("message");
119-
if (messageNode != null && messageNode.isTextual()) {
120-
return messageNode.asText();
121-
}
122-
}
123-
return "";
124-
} catch (IOException ignored) {
125-
return "";
126-
}
127-
}
128-
12972
/**
13073
* Returns the error message from the response, if no error or error message is not found, then
13174
* returns an empty string.

0 commit comments

Comments
 (0)