I am using client lib to perform a search operation. The API key used for constructing an ElasticsearchClient expired. How can I catch this specific type of "API Key expired" error, so that I can handle it, e.g. creating another key?
Caused by: co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [security_exception] unable to authenticate with provided credentials and anonymous access is not allowed for this request
at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:286)
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:111)
at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1887)
at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1904)