From f0f192c654010e2038a156add1fd777ec5f8a370 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 20 Jan 2021 11:25:48 -0700 Subject: [PATCH] [Maps] fix Maps should display better error message instead of EsError when there is no data for tracks data source (#88847) --- .../es_geo_line_source/es_geo_line_source.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx index 3693f55586b3..9c851dcedb3f 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx @@ -9,7 +9,12 @@ import React from 'react'; import { GeoJsonProperties } from 'geojson'; import { i18n } from '@kbn/i18n'; -import { FIELD_ORIGIN, SOURCE_TYPES, VECTOR_SHAPE_TYPE } from '../../../../common/constants'; +import { + EMPTY_FEATURE_COLLECTION, + FIELD_ORIGIN, + SOURCE_TYPES, + VECTOR_SHAPE_TYPE, +} from '../../../../common/constants'; import { getField, addFieldToDSL } from '../../../../common/elasticsearch_util'; import { ESGeoLineSourceDescriptor, @@ -216,6 +221,18 @@ export class ESGeoLineSource extends AbstractESAggSource { ); const totalEntities = _.get(entityResp, 'aggregations.totalEntities.value', 0); const areEntitiesTrimmed = entityBuckets.length >= MAX_TRACKS; + if (totalEntities === 0) { + return { + data: EMPTY_FEATURE_COLLECTION, + meta: { + areResultsTrimmed: false, + areEntitiesTrimmed: false, + entityCount: 0, + numTrimmedTracks: 0, + totalEntities: 0, + } as ESGeoLineSourceResponseMeta, + }; + } // // Fetch tracks