Skip to content

Commit 8ff0bb6

Browse files
Refactor error handling in BaseResponseHandler to check for error structure before type matching
1 parent f4582f3 commit 8ff0bb6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/http/retry/BaseResponseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected UnifiedChatCompletionException buildChatCompletionError(
179179
Supplier<Class<? extends ErrorResponse>> errorResponseClassSupplier,
180180
ChatCompletionErrorBuilder chatCompletionErrorBuilder
181181
) {
182-
if (errorResponseClassSupplier.get().isInstance(errorResponse)) {
182+
if (errorResponse.errorStructureFound() && errorResponseClassSupplier.get().isInstance(errorResponse)) {
183183
return chatCompletionErrorBuilder.buildProviderSpecificChatCompletionError(errorResponse, errorMessage, restStatus);
184184
} else {
185185
return buildDefaultChatCompletionError(errorResponse, errorMessage, restStatus);
@@ -233,7 +233,7 @@ protected UnifiedChatCompletionException buildMidStreamChatCompletionError(
233233
// Extract the error response from the message using the provided method
234234
var errorResponse = midStreamErrorExtractor.apply(message);
235235
// Check if the error response matches the expected type
236-
if (errorResponseClassSupplier.get().isInstance(errorResponse)) {
236+
if (errorResponse.errorStructureFound() && errorResponseClassSupplier.get().isInstance(errorResponse)) {
237237
// If it matches, we can build a custom mid-stream error exception
238238
return specificErrorBuilder.apply(inferenceEntityId, errorResponse);
239239
} else if (e != null) {

0 commit comments

Comments
 (0)