use of org.elasticsearch.ElasticsearchStatusException in project elasticsearch by elastic.
the class RemoteScrollableHitSource method wrapExceptionToPreserveStatus.
/**
* Wrap the ResponseException in an exception that'll preserve its status code if possible so we can send it back to the user. We might
* not have a constant for the status code so in that case we just use 500 instead. We also extract make sure to include the response
* body in the message so the user can figure out *why* the remote Elasticsearch service threw the error back to us.
*/
static ElasticsearchStatusException wrapExceptionToPreserveStatus(int statusCode, @Nullable HttpEntity entity, Exception cause) {
RestStatus status = RestStatus.fromCode(statusCode);
String messagePrefix = "";
if (status == null) {
messagePrefix = "Couldn't extract status [" + statusCode + "]. ";
status = RestStatus.INTERNAL_SERVER_ERROR;
}
try {
return new ElasticsearchStatusException(messagePrefix + bodyMessage(entity), status, cause);
} catch (IOException ioe) {
ElasticsearchStatusException e = new ElasticsearchStatusException(messagePrefix + "Failed to extract body.", status, cause);
e.addSuppressed(ioe);
return e;
}
}
use of org.elasticsearch.ElasticsearchStatusException in project elasticsearch by elastic.
the class ReindexFromRemoteWithAuthTests method testReindexSendsHeaders.
public void testReindexSendsHeaders() throws Exception {
ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client()).source("source").destination("dest").setRemoteInfo(newRemoteInfo(null, null, singletonMap(TestFilter.EXAMPLE_HEADER, "doesn't matter")));
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get());
assertEquals(RestStatus.BAD_REQUEST, e.status());
assertThat(e.getMessage(), containsString("Hurray! Sent the header!"));
}
use of org.elasticsearch.ElasticsearchStatusException in project elasticsearch by elastic.
the class ReindexFromRemoteWithAuthTests method testReindexWithoutAuthenticationWhenRequired.
public void testReindexWithoutAuthenticationWhenRequired() throws Exception {
ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client()).source("source").destination("dest").setRemoteInfo(newRemoteInfo(null, null, emptyMap()));
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> request.get());
assertEquals(RestStatus.UNAUTHORIZED, e.status());
assertThat(e.getMessage(), containsString("\"reason\":\"Authentication required\""));
assertThat(e.getMessage(), containsString("\"WWW-Authenticate\":\"Basic realm=auth-realm\""));
}
Aggregations