Skip to content

Commit

Permalink
throw correct error on field caps 404
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Mar 30, 2021
1 parent 80a19a8 commit 455fa8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IIndexPatternsApiClient,
GetFieldsOptionsTimePattern,
} from '../../common/index_patterns/types';
import { IndexPatternMissingIndices } from '../../common/index_patterns/lib';
import { IndexPatternsFetcher } from './fetcher';

export class IndexPatternsApiServer implements IIndexPatternsApiClient {
Expand All @@ -27,12 +28,23 @@ export class IndexPatternsApiServer implements IIndexPatternsApiClient {
allowNoIndex,
}: GetFieldsOptions) {
const indexPatterns = new IndexPatternsFetcher(this.esClient, allowNoIndex);
return await indexPatterns.getFieldsForWildcard({
pattern,
metaFields,
type,
rollupIndex,
});
return await indexPatterns
.getFieldsForWildcard({
pattern,
metaFields,
type,
rollupIndex,
})
.catch((err) => {
if (
err.output.payload.statusCode === 404 &&
err.output.payload.code === 'no_matching_indices'
) {
throw new IndexPatternMissingIndices(pattern);
} else {
throw err;
}
});
}
async getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) {
const indexPatterns = new IndexPatternsFetcher(this.esClient);
Expand Down
11 changes: 3 additions & 8 deletions x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ async function isFieldGeoShape(
if (!indexPattern) {
return false;
}
const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern(indexPattern);
return fieldsForIndexPattern.some(
return indexPattern.fields.some(
(fieldDescriptor: IFieldType) => fieldDescriptor.name && fieldDescriptor.name === geoField!
);
}
Expand Down Expand Up @@ -192,13 +191,9 @@ async function filterIndexPatternsByField(fields: string[]) {
await Promise.all(
indexPatternIds.map(async (indexPatternId: string) => {
const indexPattern = await indexPatternsService.get(indexPatternId);
const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern(
indexPattern
);
const containsField = fields.some((field: string) =>
fieldsForIndexPattern.some(
(fieldDescriptor: IFieldType) =>
fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field)
indexPattern.fields.some(
(fieldDescriptor) => fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field)
)
);
if (containsField) {
Expand Down

0 comments on commit 455fa8d

Please sign in to comment.