diff --git a/x-pack/plugins/observability/public/hooks/slo/use_get_preview_data.ts b/x-pack/plugins/observability/public/hooks/slo/use_get_preview_data.ts index f9ebff032b5da..0dfe9cbebc82d 100644 --- a/x-pack/plugins/observability/public/hooks/slo/use_get_preview_data.ts +++ b/x-pack/plugins/observability/public/hooks/slo/use_get_preview_data.ts @@ -42,7 +42,7 @@ export function useGetPreviewData(isValid: boolean, indicator: Indicator): UseGe } ); - return response; + return Array.isArray(response) ? response : []; }, retry: false, refetchOnWindowFocus: false, diff --git a/x-pack/plugins/observability/server/services/slo/get_preview_data.ts b/x-pack/plugins/observability/server/services/slo/get_preview_data.ts index e85085dcec115..98f07e1f8ed5e 100644 --- a/x-pack/plugins/observability/server/services/slo/get_preview_data.ts +++ b/x-pack/plugins/observability/server/services/slo/get_preview_data.ts @@ -16,12 +16,13 @@ import { KQLCustomIndicator, MetricCustomIndicator, } from '@kbn/slo-schema'; +import { assertNever } from '@kbn/std'; import { APMTransactionDurationIndicator } from '../../domain/models'; import { computeSLI } from '../../domain/services'; import { InvalidQueryError } from '../../errors'; import { - GetHistogramIndicatorAggregation, GetCustomMetricIndicatorAggregation, + GetHistogramIndicatorAggregation, } from './aggregations'; export class GetPreviewData { @@ -299,19 +300,24 @@ export class GetPreviewData { } public async execute(params: GetPreviewDataParams): Promise { - switch (params.indicator.type) { - case 'sli.apm.transactionDuration': - return this.getAPMTransactionDurationPreviewData(params.indicator); - case 'sli.apm.transactionErrorRate': - return this.getAPMTransactionErrorPreviewData(params.indicator); - case 'sli.kql.custom': - return this.getCustomKQLPreviewData(params.indicator); - case 'sli.histogram.custom': - return this.getHistogramPreviewData(params.indicator); - case 'sli.metric.custom': - return this.getCustomMetricPreviewData(params.indicator); - default: - return []; + try { + const type = params.indicator.type; + switch (type) { + case 'sli.apm.transactionDuration': + return this.getAPMTransactionDurationPreviewData(params.indicator); + case 'sli.apm.transactionErrorRate': + return this.getAPMTransactionErrorPreviewData(params.indicator); + case 'sli.kql.custom': + return this.getCustomKQLPreviewData(params.indicator); + case 'sli.histogram.custom': + return this.getHistogramPreviewData(params.indicator); + case 'sli.metric.custom': + return this.getCustomMetricPreviewData(params.indicator); + default: + assertNever(type); + } + } catch (err) { + return []; } } }