From f0f86d1f2e4d12edeefa872c8a5a62615d9c7d5b Mon Sep 17 00:00:00 2001
From: Tyler Ohlsen <ohltyler@amazon.com>
Date: Mon, 11 May 2020 10:46:11 -0700
Subject: [PATCH 1/2] 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..9141bc73 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', err);
+      setIsLoadingAnomalies(false);
+    }
 
     setHasLatestAnomalyResult(!isEmpty(latestSingleLiveAnomalyResult));
 

From d813f94e25bd6675f59dbaf4aaf96407d8f64841 Mon Sep 17 00:00:00 2001
From: Tyler Ohlsen <ohltyler@amazon.com>
Date: Mon, 11 May 2020 10:48:18 -0700
Subject: [PATCH 2/2] Change console wording

---
 public/pages/Dashboard/Components/AnomaliesLiveChart.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx b/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx
index 9141bc73..cd3ee318 100644
--- a/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx
+++ b/public/pages/Dashboard/Components/AnomaliesLiveChart.tsx
@@ -109,7 +109,7 @@ export const AnomaliesLiveChart = (props: AnomaliesLiveChartProps) => {
         true
       );
     } catch (err) {
-      console.log('Error getting latest anomaly results', err);
+      console.log('Error getting latest anomaly results - index may not exist yet', err);
       setIsLoadingAnomalies(false);
     }