From d7abac08ef91de438a99a133cf7c95cfe55b3808 Mon Sep 17 00:00:00 2001 From: Su Date: Tue, 4 Oct 2022 17:49:32 -0700 Subject: [PATCH 1/2] add error toast for create index pattern with data source Signed-off-by: Su --- .../create_index_pattern_wizard.tsx | 1 + .../lib/get_indices.test.ts | 18 ++++++++++++++++-- .../lib/get_indices.ts | 9 ++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx index f0f0563eee87..4083cb3d3700 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/create_index_pattern_wizard.tsx @@ -134,6 +134,7 @@ export class CreateIndexPatternWizard extends Component< id: errorMsg.props.id, color: 'warning', iconType: 'alert', + text: errors.body.message, }, ]), })); diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.test.ts b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.test.ts index 56ae8515ddde..4cafe9e1d195 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.test.ts +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.test.ts @@ -119,7 +119,7 @@ describe('getIndices', () => { expect(result[1].name).toBe('foo'); }); - it('should make two calls in cross cluser case', async () => { + it('should make two calls in cross cluster case', async () => { http.get.mockResolvedValue(successfulResolveResponse); const result = await getIndices({ http, @@ -201,9 +201,23 @@ describe('getIndices', () => { getIndexTags, pattern: 'opensearch-dashboards', searchClient, - dataSourceId, }); expect(result.length).toBe(0); }); + + it('should throw error with data source use case', async () => { + http.get.mockImplementationOnce(() => { + throw new Error('Test error'); + }); + expect( + getIndices({ + http, + getIndexTags, + pattern: 'opensearch-dashboards', + searchClient, + dataSourceId, + }) + ).rejects.toThrowError(); + }); }); }); diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.ts b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.ts index 39bd044d8011..0130bbac2df2 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.ts +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/get_indices.ts @@ -199,7 +199,14 @@ export async function getIndices({ pattern, showAllIndices, dataSourceId, - }).catch(() => []); + }).catch((error) => { + // swallow the errors to be backwards compatible with non-data-source use case + if (dataSourceId) { + throw error; + } else { + return []; + } + }); requests.push(promiseResolve); if (isCCS) { From 558f0f935bd102714e64d29a8928b0dc4138ce0e Mon Sep 17 00:00:00 2001 From: Su Date: Tue, 4 Oct 2022 18:03:05 -0700 Subject: [PATCH 2/2] update change log Signed-off-by: Su --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df35a1f20ba5..083331ef5555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * [MD] Support legacy client for data source ([#2204](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2204)) * [Plugin Helpers] Facilitate version changes ([#2398](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2398)) +* [MD] Display error toast for create index pattern with data source ([#2506](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2506)) ### 🐛 Bug Fixes * [Vis Builder] Fixes auto bounds for timeseries bar chart visualization ([2401](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2401))