Exists API can send response body, closes #2072.
This commit is contained in:
parent
3ab85bacdd
commit
bdf146ded6
|
@ -21,6 +21,7 @@ package org.elasticsearch;
|
||||||
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
|
import org.elasticsearch.rest.RestStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -29,6 +30,13 @@ public final class ExceptionsHelper {
|
||||||
|
|
||||||
private static final ESLogger logger = Loggers.getLogger(ExceptionsHelper.class);
|
private static final ESLogger logger = Loggers.getLogger(ExceptionsHelper.class);
|
||||||
|
|
||||||
|
public static RestStatus status(Throwable t) {
|
||||||
|
if (t instanceof ElasticSearchException) {
|
||||||
|
return ((ElasticSearchException) t).status();
|
||||||
|
}
|
||||||
|
return RestStatus.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
public static Throwable unwrapCause(Throwable t) {
|
public static Throwable unwrapCause(Throwable t) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
Throwable result = t;
|
Throwable result = t;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.rest.action.admin.indices.exists;
|
package org.elasticsearch.rest.action.admin.indices.exists;
|
||||||
|
|
||||||
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
|
import org.elasticsearch.action.admin.indices.exists.IndicesExistsRequest;
|
||||||
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
|
import org.elasticsearch.action.admin.indices.exists.IndicesExistsResponse;
|
||||||
|
@ -70,7 +71,7 @@ public class RestIndicesExistsAction extends BaseRestHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable e) {
|
public void onFailure(Throwable e) {
|
||||||
try {
|
try {
|
||||||
channel.sendResponse(new XContentThrowableRestResponse(request, e));
|
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
logger.error("Failed to send failure response", e1);
|
logger.error("Failed to send failure response", e1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.rest.action.get;
|
package org.elasticsearch.rest.action.get;
|
||||||
|
|
||||||
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.get.GetRequest;
|
import org.elasticsearch.action.get.GetRequest;
|
||||||
import org.elasticsearch.action.get.GetResponse;
|
import org.elasticsearch.action.get.GetResponse;
|
||||||
|
@ -28,8 +29,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.*;
|
import org.elasticsearch.rest.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
||||||
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
|
@ -76,8 +75,8 @@ public class RestHeadAction extends BaseRestHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable e) {
|
public void onFailure(Throwable e) {
|
||||||
try {
|
try {
|
||||||
channel.sendResponse(new XContentThrowableRestResponse(request, e));
|
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
|
||||||
} catch (IOException e1) {
|
} catch (Exception e1) {
|
||||||
logger.error("Failed to send failure response", e1);
|
logger.error("Failed to send failure response", e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.rest.action.main;
|
package org.elasticsearch.rest.action.main;
|
||||||
|
|
||||||
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||||
|
@ -31,8 +32,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.*;
|
import org.elasticsearch.rest.*;
|
||||||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
||||||
|
|
||||||
|
@ -88,8 +87,12 @@ public class RestMainAction extends BaseRestHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable e) {
|
public void onFailure(Throwable e) {
|
||||||
try {
|
try {
|
||||||
|
if (request.method() == HEAD) {
|
||||||
|
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
|
||||||
|
} else {
|
||||||
channel.sendResponse(new XContentThrowableRestResponse(request, e));
|
channel.sendResponse(new XContentThrowableRestResponse(request, e));
|
||||||
} catch (IOException e1) {
|
}
|
||||||
|
} catch (Exception e1) {
|
||||||
logger.warn("Failed to send response", e);
|
logger.warn("Failed to send response", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue