Skip to content

Commit 455fa8d

Browse files
committed
throw correct error on field caps 404
1 parent 80a19a8 commit 455fa8d

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/plugins/data/server/index_patterns/index_patterns_api_client.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
IIndexPatternsApiClient,
1313
GetFieldsOptionsTimePattern,
1414
} from '../../common/index_patterns/types';
15+
import { IndexPatternMissingIndices } from '../../common/index_patterns/lib';
1516
import { IndexPatternsFetcher } from './fetcher';
1617

1718
export class IndexPatternsApiServer implements IIndexPatternsApiClient {
@@ -27,12 +28,23 @@ export class IndexPatternsApiServer implements IIndexPatternsApiClient {
2728
allowNoIndex,
2829
}: GetFieldsOptions) {
2930
const indexPatterns = new IndexPatternsFetcher(this.esClient, allowNoIndex);
30-
return await indexPatterns.getFieldsForWildcard({
31-
pattern,
32-
metaFields,
33-
type,
34-
rollupIndex,
35-
});
31+
return await indexPatterns
32+
.getFieldsForWildcard({
33+
pattern,
34+
metaFields,
35+
type,
36+
rollupIndex,
37+
})
38+
.catch((err) => {
39+
if (
40+
err.output.payload.statusCode === 404 &&
41+
err.output.payload.code === 'no_matching_indices'
42+
) {
43+
throw new IndexPatternMissingIndices(pattern);
44+
} else {
45+
throw err;
46+
}
47+
});
3648
}
3749
async getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) {
3850
const indexPatterns = new IndexPatternsFetcher(this.esClient);

x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ async function isFieldGeoShape(
125125
if (!indexPattern) {
126126
return false;
127127
}
128-
const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern(indexPattern);
129-
return fieldsForIndexPattern.some(
128+
return indexPattern.fields.some(
130129
(fieldDescriptor: IFieldType) => fieldDescriptor.name && fieldDescriptor.name === geoField!
131130
);
132131
}
@@ -192,13 +191,9 @@ async function filterIndexPatternsByField(fields: string[]) {
192191
await Promise.all(
193192
indexPatternIds.map(async (indexPatternId: string) => {
194193
const indexPattern = await indexPatternsService.get(indexPatternId);
195-
const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern(
196-
indexPattern
197-
);
198194
const containsField = fields.some((field: string) =>
199-
fieldsForIndexPattern.some(
200-
(fieldDescriptor: IFieldType) =>
201-
fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field)
195+
indexPattern.fields.some(
196+
(fieldDescriptor) => fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field)
202197
)
203198
);
204199
if (containsField) {

0 commit comments

Comments
 (0)