From 5c78364fcc1b36356cc31a66bacf3ebb8ca96b65 Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Mon, 11 May 2020 11:31:46 -0700 Subject: [PATCH] Fix loading bug on anomalies live chart (#129) * Fix loading bug on live anomalies chart --- .../Components/AnomaliesLiveChart.tsx | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx b/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx index 41eb8689..cd3ee318 100644 --- a/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx +++ b/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx @@ -96,14 +96,22 @@ export const AnomaliesLiveChart = (props: AnomaliesLiveChartProps) => { const getLiveAnomalyResults = async () => { setIsLoadingAnomalies(true); // check if there is any anomaly result in last 30mins - const latestSingleLiveAnomalyResult = await getLatestAnomalyResultsByTimeRange( - searchES, - '30m', - dispatch, - -1, - 1, - true - ); + // need to initially check if there is an error when accessing anomaly results index + // in the case that it doesn't exist upon cluster initialization + let latestSingleLiveAnomalyResult = [] as any[]; + try { + latestSingleLiveAnomalyResult = await getLatestAnomalyResultsByTimeRange( + searchES, + '30m', + dispatch, + -1, + 1, + true + ); + } catch (err) { + console.log('Error getting latest anomaly results - index may not exist yet', err); + setIsLoadingAnomalies(false); + } setHasLatestAnomalyResult(!isEmpty(latestSingleLiveAnomalyResult));