elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

Should `ElasticsearchIndicesClient#existsIndexTemplate()` with invalid credentials return `false` or `ElasticsearchException(security_exception, 401)`

Open cyrille-leclerc opened this issue 2 years ago • 1 comments

Java API client version

8.1.0

Java version

openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9) OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)

Elasticsearch Version

8.1.0

Problem description

ElasticsearchIndicesClient#existsIndexTemplate() with invalid credentials returns false when I expected the returned valued to be an ElasticsearchException(security_exception, 401) that would have been consistent with the returned value of methods like ElasticsearchIlmClient#getLifecycle().

Could you please clarify the expected behaviour? I expected an ElasticsearchException(security_exception, 401) and got surprised.

See https://github.com/jenkinsci/opentelemetry-plugin/blob/opentelemetry-2.3.0-rc1/src/main/java/io/jenkins/plugins/opentelemetry/backend/elastic/ElasticsearchLogStorageRetriever.java#L218-L243

cyrille-leclerc avatar Mar 21 '22 10:03 cyrille-leclerc

This is actually a bug related to the fact that this is a HEAD request that doesn't return a JSON error reponse. We have to create the error response in the client in this case.

swallez avatar May 05 '22 15:05 swallez