[ML] Use ExceptionsHelper.convertToElastic to wrap exceptions in TransportJobTaskAction (elastic/x-pack-elasticsearch#577)
* Wrap exceptions if they are not ElasticsearchExceptions in TransportJobTaskAction
* Review comments
Original commit: elastic/x-pack-elasticsearch@07e900ffaabd2451ee5b1533b68a8236d202a2d9
@@ -96,9 +96,9 @@ public abstract class TransportJobTaskAction<OperationTask extends Task, Request
// the actionlistener's onFailure
if (tasks.isEmpty()) {
if (taskOperationFailures.isEmpty() == false) {
- throw new ElasticsearchException(taskOperationFailures.get(0).getCause());
+ throw wrapThrowable(taskOperationFailures.get(0).getCause());
} else if (failedNodeExceptions.isEmpty() == false) {
- throw new ElasticsearchException(failedNodeExceptions.get(0).getCause());
+ throw wrapThrowable(failedNodeExceptions.get(0).getCause());
} else {
throw new IllegalStateException("No errors or response");
}
@@ -110,6 +110,14 @@ public abstract class TransportJobTaskAction<OperationTask extends Task, Request
}
}
+ private ElasticsearchException wrapThrowable(Throwable th) {
+ if (th instanceof ElasticsearchException) {
+ return (ElasticsearchException) th;
+ } else {
+ return new ElasticsearchException(th);
+ }
+ }
+
@Override
protected boolean accumulateExceptions() {
return false;
