[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@07e900ffaa
This commit is contained in:
David Kyle 2017-02-22 10:03:22 +00:00 committed by GitHub
parent 45ecebac20
commit f82634b6b1
1 changed files with 10 additions and 2 deletions

View File

@ -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;