Skip to content

Commit c123381

Browse files
committed
Add new InferenceException, exposing status by wrapped execption
1 parent 8927706 commit c123381

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference;
9+
10+
import org.elasticsearch.ElasticsearchException;
11+
import org.elasticsearch.ElasticsearchWrapperException;
12+
import org.elasticsearch.ExceptionsHelper;
13+
import org.elasticsearch.rest.RestStatus;
14+
15+
public class InferenceException extends ElasticsearchException implements ElasticsearchWrapperException {
16+
public InferenceException(String message, Throwable cause, Object... args) {
17+
super(message, cause, args);
18+
}
19+
20+
@Override
21+
public RestStatus status() {
22+
return ExceptionsHelper.status(unwrapCause());
23+
}
24+
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilter.java

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

88
package org.elasticsearch.xpack.inference.action.filter;
99

10-
import org.elasticsearch.ElasticsearchException;
1110
import org.elasticsearch.ElasticsearchStatusException;
1211
import org.elasticsearch.ExceptionsHelper;
1312
import org.elasticsearch.ResourceNotFoundException;
@@ -46,6 +45,7 @@
4645
import org.elasticsearch.xcontent.XContent;
4746
import org.elasticsearch.xpack.core.XPackField;
4847
import org.elasticsearch.xpack.core.inference.results.ChunkedInferenceError;
48+
import org.elasticsearch.xpack.inference.InferenceException;
4949
import org.elasticsearch.xpack.inference.mapper.SemanticTextField;
5050
import org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper;
5151
import org.elasticsearch.xpack.inference.mapper.SemanticTextUtils;
@@ -290,14 +290,12 @@ public void onFailure(Exception exc) {
290290
request.field
291291
);
292292
} else {
293-
failure = exc instanceof ElasticsearchException
294-
? exc
295-
: new ElasticsearchException(
296-
"Error loading inference for inference id [{}] on field [{}]",
297-
exc,
298-
inferenceId,
299-
request.field
300-
);
293+
failure = new InferenceException(
294+
"Error loading inference for inference id [{}] on field [{}]",
295+
exc,
296+
inferenceId,
297+
request.field
298+
);
301299
}
302300
inferenceResults.get(request.index).failures.add(failure);
303301
}
@@ -321,14 +319,12 @@ public void onResponse(List<ChunkedInference> results) {
321319
var acc = inferenceResults.get(request.index);
322320
if (result instanceof ChunkedInferenceError error) {
323321
acc.addFailure(
324-
error.exception() instanceof ElasticsearchException
325-
? error.exception()
326-
: new ElasticsearchException(
327-
"Exception when running inference id [{}] on field [{}]",
328-
error.exception(),
329-
inferenceProvider.model.getInferenceEntityId(),
330-
request.field
331-
)
322+
new InferenceException(
323+
"Exception when running inference id [{}] on field [{}]",
324+
error.exception(),
325+
inferenceProvider.model.getInferenceEntityId(),
326+
request.field
327+
)
332328
);
333329
} else {
334330
acc.addOrUpdateResponse(
@@ -355,14 +351,12 @@ public void onFailure(Exception exc) {
355351
for (FieldInferenceRequest request : requests) {
356352
addInferenceResponseFailure(
357353
request.index,
358-
exc instanceof ElasticsearchException
359-
? exc
360-
: new ElasticsearchException(
361-
"Exception when running inference id [{}] on field [{}]",
362-
exc,
363-
inferenceProvider.model.getInferenceEntityId(),
364-
request.field
365-
)
354+
new InferenceException(
355+
"Exception when running inference id [{}] on field [{}]",
356+
exc,
357+
inferenceProvider.model.getInferenceEntityId(),
358+
request.field
359+
)
366360
);
367361
}
368362
} finally {

0 commit comments

Comments
 (0)