diff --git a/public/components/trace_analytics/requests/request_handler.ts b/public/components/trace_analytics/requests/request_handler.ts index 494aa9b09..2d3191a02 100644 --- a/public/components/trace_analytics/requests/request_handler.ts +++ b/public/components/trace_analytics/requests/request_handler.ts @@ -2,7 +2,6 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ -/* eslint-disable no-console */ import { CoreStart } from '../../../../../../src/core/public'; import { @@ -10,11 +9,18 @@ import { TRACE_ANALYTICS_DATA_PREPPER_INDICES_ROUTE, TRACE_ANALYTICS_JAEGER_INDICES_ROUTE, JAEGER_INDEX_NAME, - DATA_PREPPER_INDEX_NAME + DATA_PREPPER_INDEX_NAME, } from '../../../../common/constants/trace_analytics'; import { TraceAnalyticsMode } from '../home'; -export function handleDslRequest(http: CoreStart['http'], DSL: any, bodyQuery: any, mode: TraceAnalyticsMode, timeout?: boolean, setShowTimeoutToast?: () => void) { +export async function handleDslRequest( + http: CoreStart['http'], + DSL: any, + bodyQuery: any, + mode: TraceAnalyticsMode, + timeout?: boolean, + setShowTimeoutToast?: () => void +) { if (DSL?.query) { bodyQuery.query.bool.must.push(...DSL.query.bool.must); bodyQuery.query.bool.filter.push(...DSL.query.bool.filter); @@ -25,35 +31,45 @@ export function handleDslRequest(http: CoreStart['http'], DSL: any, bodyQuery: a } let body = bodyQuery; if (!bodyQuery.index) { - body = {...bodyQuery, index: ((mode === 'jaeger' ? JAEGER_INDEX_NAME : DATA_PREPPER_INDEX_NAME)) } + body = { ...bodyQuery, index: mode === 'jaeger' ? JAEGER_INDEX_NAME : DATA_PREPPER_INDEX_NAME }; } if (timeout) { const id = setTimeout(() => setShowTimeoutToast!(), 30000); - return http - .post(TRACE_ANALYTICS_DSL_ROUTE, { + + try { + return await http.post(TRACE_ANALYTICS_DSL_ROUTE, { body: JSON.stringify(body), - }) - .catch((error) => { - console.error(error) - }) - .finally(() => clearTimeout(id)); + }); + } catch (error) { + console.error(error); + } finally { + clearTimeout(id); + } } - return http - .post(TRACE_ANALYTICS_DSL_ROUTE, { + try { + return await http.post(TRACE_ANALYTICS_DSL_ROUTE, { body: JSON.stringify(body), - }) - .catch((error) => console.error(error)); + }); + } catch (error_1) { + console.error(error_1); + } } -export async function handleJaegerIndicesExistRequest(http: CoreStart['http'], setJaegerIndicesExist) { +export async function handleJaegerIndicesExistRequest( + http: CoreStart['http'], + setJaegerIndicesExist +) { http .post(TRACE_ANALYTICS_JAEGER_INDICES_ROUTE) .then((exists) => setJaegerIndicesExist(exists)) .catch(() => setJaegerIndicesExist(false)); } -export async function handleDataPrepperIndicesExistRequest(http: CoreStart['http'], setDataPrepperIndicesExist) { +export async function handleDataPrepperIndicesExistRequest( + http: CoreStart['http'], + setDataPrepperIndicesExist +) { http .post(TRACE_ANALYTICS_DATA_PREPPER_INDICES_ROUTE) .then((exists) => setDataPrepperIndicesExist(exists))