diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 57d82c14d73..83be9f43ee6 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -661,4 +661,19 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } return null; } + + public static void renderThrowable(XContentBuilder builder, Params params, Throwable t) throws IOException { + builder.startObject("error"); + final ElasticsearchException[] rootCauses = ElasticsearchException.guessRootCauses(t); + builder.field("root_cause"); + builder.startArray(); + for (ElasticsearchException rootCause : rootCauses){ + builder.startObject(); + rootCause.toXContent(builder, new ToXContent.DelegatingMapParams(Collections.singletonMap(ElasticsearchException.REST_EXCEPTION_SKIP_CAUSE, "true"), params)); + builder.endObject(); + } + builder.endArray(); + ElasticsearchException.toXContent(builder, params, t); + builder.endObject(); + } } diff --git a/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java b/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java index 2efb90bc3a1..7abfb2b7d61 100644 --- a/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java +++ b/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java @@ -20,7 +20,9 @@ package org.elasticsearch.action.get; import com.google.common.collect.Iterators; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.percolate.PercolateResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -29,6 +31,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; +import java.util.Collections; import java.util.Iterator; public class MultiGetResponse extends ActionResponse implements Iterable, ToXContent { @@ -40,17 +43,17 @@ public class MultiGetResponse extends ActionResponse implements Iterablenull if there was error. - */ - @Nullable - public PercolateResponse response() { - return response; - } - - /** - * @return An error description if there was an error or null if the percolate request was successful - */ - @Nullable - public String errorMessage() { - return errorMessage; - } /** * @return The percolator response or null if there was error. @@ -154,7 +138,7 @@ public class MultiPercolateResponse extends ActionResponse implements Iterablefalse is returned. */ public boolean isFailure() { - return errorMessage != null; + return throwable != null; + } + + public Throwable getFailure() { + return throwable; } @Override @@ -171,7 +159,7 @@ public class MultiPercolateResponse extends ActionResponse implements Iterable