From 4656c203bf95e4a4243883c9a38e08ec5662e75e Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 21 Feb 2025 04:00:07 +1100 Subject: [PATCH] [9.0] [scout] Don't mix `await` with promise callbacks (#211905) (#211916) # Backport This will backport the following commits from `main` to `9.0`: - [[scout] Don't mix `await` with promise callbacks (#211905)](https://github.com/elastic/kibana/pull/211905) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) Co-authored-by: David Olaru --- .../src/helpers/elasticsearch.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/kbn-scout-reporting/src/helpers/elasticsearch.ts b/packages/kbn-scout-reporting/src/helpers/elasticsearch.ts index fec91fa7718b6..d49b1b8244c26 100644 --- a/packages/kbn-scout-reporting/src/helpers/elasticsearch.ts +++ b/packages/kbn-scout-reporting/src/helpers/elasticsearch.ts @@ -30,17 +30,15 @@ export async function getValidatedESClient( const { log, cli = false } = helperSettings; const es = new ESClient(esClientOptions); - await es.info().then( - (esInfo) => { - if (log !== undefined) { - log.info(`Connected to Elasticsearch node '${esInfo.name}'`); - } - }, - (err) => { - const msg = `Failed to connect to Elasticsearch\n${err}`; - throw cli ? createFailError(msg) : Error(msg); + try { + const esInfo = await es.info(); + if (log !== undefined) { + log.info(`Connected to Elasticsearch node '${esInfo.name}'`); } - ); + } catch (err) { + const msg = `Failed to connect to Elasticsearch\n${err}`; + throw cli ? createFailError(msg) : Error(msg); + } return es; }