Skip to content

Commit 82f8049

Browse files
Refactor error handling in HuggingFaceServiceTests to standardize error response codes and types
1 parent aae528a commit 82f8049

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/HuggingFaceServiceTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ public void testUnifiedCompletionError() throws Exception {
352352
{
353353
"error": {
354354
"message": "The model `gpt-4awero` does not exist or you do not have access to it.",
355-
"type": "invalid_request_error",
356-
"param": null,
357-
"code": "model_not_found"
355+
"http_status_code": "404"
358356
}
359357
}""";
360358
webServer.enqueue(new MockResponse().setResponseCode(404).setBody(responseJson));
@@ -385,10 +383,10 @@ public void testUnifiedCompletionError() throws Exception {
385383
assertThat(json, is("""
386384
{\
387385
"error":{\
388-
"code":"model_not_found",\
386+
"code":"404",\
389387
"message":"Received an unsuccessful status code for request from inference entity id [id] status \
390388
[404]. Error message: [The model `gpt-4awero` does not exist or you do not have access to it.]",\
391-
"type":"invalid_request_error"\
389+
"type":"HuggingFaceErrorResponse"\
392390
}}"""));
393391
} catch (IOException ex) {
394392
throw new RuntimeException(ex);
@@ -402,7 +400,7 @@ public void testUnifiedCompletionError() throws Exception {
402400
public void testMidStreamUnifiedCompletionError() throws Exception {
403401
String responseJson = """
404402
event: error
405-
data: { "error": { "message": "Timed out waiting for more data", "type": "timeout" } }
403+
data: { "error": { "message": "Timed out waiting for more data" } }
406404
407405
""";
408406
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
@@ -411,7 +409,7 @@ public void testMidStreamUnifiedCompletionError() throws Exception {
411409
"error":{\
412410
"message":"Received an error response for request from inference entity id [id]. Error message: \
413411
[Timed out waiting for more data]",\
414-
"type":"timeout"\
412+
"type":"HuggingFaceErrorResponse"\
415413
}}""");
416414
}
417415

0 commit comments

Comments
 (0)