mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[DataViews] Improve error handling of resolving indices (#164400)
When in data view management an exact match index pattern is entered (without wildcard), there's now a status code of 404 instead of 500 returned, and no more error message logged.
This commit is contained in:
parent
37195cc0b9
commit
76ac34a9b7
4 changed files with 53 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { IRouter } from '@kbn/core/server';
|
||||
import { getKbnServerError } from '@kbn/kibana-utils-plugin/server';
|
||||
|
||||
export function registerResolveIndexRoute(router: IRouter): void {
|
||||
router.get(
|
||||
|
@ -32,11 +33,19 @@ export function registerResolveIndexRoute(router: IRouter): void {
|
|||
},
|
||||
async (context, req, res) => {
|
||||
const esClient = (await context.core).elasticsearch.client;
|
||||
const body = await esClient.asCurrentUser.indices.resolveIndex({
|
||||
name: req.params.query,
|
||||
expand_wildcards: req.query.expand_wildcards || 'open',
|
||||
});
|
||||
return res.ok({ body });
|
||||
try {
|
||||
const body = await esClient.asCurrentUser.indices.resolveIndex({
|
||||
name: req.params.query,
|
||||
expand_wildcards: req.query.expand_wildcards || 'open',
|
||||
});
|
||||
return res.ok({ body });
|
||||
} catch (e) {
|
||||
if (e?.meta.statusCode === 404) {
|
||||
return res.notFound({ body: { message: e.meta?.body?.error?.reason } });
|
||||
} else {
|
||||
throw getKbnServerError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -21,5 +21,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
|
|||
loadTestFile(require.resolve('./deprecations'));
|
||||
loadTestFile(require.resolve('./has_user_index_pattern'));
|
||||
loadTestFile(require.resolve('./swap_references'));
|
||||
loadTestFile(require.resolve('./resolve_index'));
|
||||
});
|
||||
}
|
||||
|
|
15
test/api_integration/apis/data_views/resolve_index/index.ts
Normal file
15
test/api_integration/apis/data_views/resolve_index/index.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { FtrProviderContext } from '../../../ftr_provider_context';
|
||||
|
||||
export default function ({ loadTestFile }: FtrProviderContext) {
|
||||
describe('/internal/index-pattern-management/resolve_index', () => {
|
||||
loadTestFile(require.resolve('./resolve_index'));
|
||||
});
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { FtrProviderContext } from '../../../ftr_provider_context';
|
||||
|
||||
// node scripts/functional_tests --config test/api_integration/config.js --grep="Resolve index API"
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
|
||||
describe('Resolve index API', function () {
|
||||
it('should return 200 for a search for indices with wildcard', () =>
|
||||
supertest.get(`/internal/index-pattern-management/resolve_index/test*`).expect(200));
|
||||
|
||||
it('should return 404 for an exact match index', () =>
|
||||
supertest.get(`/internal/index-pattern-management/resolve_index/test`).expect(404));
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue