diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java index f42ea73745c..978e4668acc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesRequest.java @@ -36,7 +36,8 @@ public class GetIndexTemplatesRequest extends MasterNodeOperationRequest() { @Override public void onResponse(GetIndexTemplatesResponse getIndexTemplatesResponse) { try { boolean templateExists = getIndexTemplatesResponse.getIndexTemplates().size() > 0; - if (!templateExists) { - channel.sendResponse(new StringRestResponse(NOT_FOUND)); - } else { - Map paramsMap = Maps.newHashMap(); - paramsMap.put("reduce_mappings", "true"); - ToXContent.Params params = new ToXContent.DelegatingMapParams(paramsMap, request); + Map paramsMap = Maps.newHashMap(); + paramsMap.put("reduce_mappings", "true"); + ToXContent.Params params = new ToXContent.DelegatingMapParams(paramsMap, request); - XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); - builder.startObject(); - for (IndexTemplateMetaData indexTemplateMetaData : getIndexTemplatesResponse.getIndexTemplates()) { - IndexTemplateMetaData.Builder.toXContent(indexTemplateMetaData, builder, params); - } - builder.endObject(); - - channel.sendResponse(new XContentRestResponse(request, OK, builder)); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); + builder.startObject(); + for (IndexTemplateMetaData indexTemplateMetaData : getIndexTemplatesResponse.getIndexTemplates()) { + IndexTemplateMetaData.Builder.toXContent(indexTemplateMetaData, builder, params); } + builder.endObject(); + + RestStatus restStatus = (templateExists || implicitAll) ? OK : NOT_FOUND; + + channel.sendResponse(new XContentRestResponse(request, restStatus, builder)); } catch (Throwable e) { onFailure(e); } @@ -90,7 +89,7 @@ public class RestGetIndexTemplateAction extends BaseRestHandler { @Override public void onFailure(Throwable e) { try { - channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e))); + channel.sendResponse(new XContentThrowableRestResponse(request, e)); } catch (Exception e1) { logger.error("Failed to send failure response", e1); }