Skip to content

Commit 7b99b1d

Browse files
committed
Returning whole body when fail to parse response from VertexAI
1 parent 93a7ca7 commit 7b99b1d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiUnifiedChatCompletionResponseHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.inference.services.googlevertexai;
99

10+
import org.elasticsearch.common.Strings;
1011
import org.elasticsearch.core.Nullable;
1112
import org.elasticsearch.inference.InferenceServiceResults;
1213
import org.elasticsearch.logging.LogManager;
@@ -27,6 +28,7 @@
2728
import org.elasticsearch.xpack.inference.external.response.streaming.ServerSentEventParser;
2829
import org.elasticsearch.xpack.inference.external.response.streaming.ServerSentEventProcessor;
2930

31+
import java.nio.charset.StandardCharsets;
3032
import java.util.Locale;
3133
import java.util.Objects;
3234
import java.util.Optional;
@@ -143,9 +145,9 @@ static ErrorResponse fromResponse(HttpResult response) {
143145
) {
144146
return ERROR_PARSER.apply(parser, null).orElse(ErrorResponse.UNDEFINED_ERROR);
145147
} catch (Exception e) {
146-
logger.warn("Failed to parse Google Vertex AI error response body", e);
148+
var resultAsString = new String(response.body(), StandardCharsets.UTF_8);
149+
return new ErrorResponse(Strings.format("Unable to parse the Google Vertex AI error, response body: [%s]", resultAsString));
147150
}
148-
return ErrorResponse.UNDEFINED_ERROR;
149151
}
150152

151153
static ErrorResponse fromString(String response) {
@@ -155,9 +157,8 @@ static ErrorResponse fromString(String response) {
155157
) {
156158
return ERROR_PARSER.apply(parser, null).orElse(ErrorResponse.UNDEFINED_ERROR);
157159
} catch (Exception e) {
158-
logger.warn("Failed to parse Google Vertex AI error string", e);
160+
return new ErrorResponse(Strings.format("Unable to parse the Google Vertex AI error, response body: [%s]", response));
159161
}
160-
return ErrorResponse.UNDEFINED_ERROR;
161162
}
162163

163164
private final int code;

0 commit comments

Comments
 (0)