From 8fc0dfcda6ed0718e88ad018d6099de74e823b75 Mon Sep 17 00:00:00 2001 From: Su Date: Thu, 23 Mar 2023 11:50:48 -0700 Subject: [PATCH] update error handling Signed-off-by: Su --- src/plugins/data/common/index_patterns/utils.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/common/index_patterns/utils.ts b/src/plugins/data/common/index_patterns/utils.ts index 92fa20001b0c..ac0a253b1c29 100644 --- a/src/plugins/data/common/index_patterns/utils.ts +++ b/src/plugins/data/common/index_patterns/utils.ts @@ -83,11 +83,20 @@ export const getIndexPatternTitle = async ( getDataSource: (id: string) => Promise> ): Promise => { const DELIMITER = '.'; + let dataSourceTitle; // If an index-pattern references datasource, prepend data source name with index pattern name for display purpose if (Array.isArray(references) && references[0] && references[0].type === 'data-source') { - const { - attributes: { title: dataSourceTitle }, - } = await getDataSource(references[0].id); + const dataSourceId = references[0].id; + try { + const { + attributes: { title }, + error, + } = await getDataSource(dataSourceId); + dataSourceTitle = error ? dataSourceId : title; + } catch (e) { + dataSourceTitle = dataSourceId; + } + return dataSourceTitle.concat(DELIMITER).concat(indexPatternTitle); } else { // if index pattern doesn't reference datasource, return as it is.