Skip to content

Commit

Permalink
[7.x] [ES UI] Error handling (#68809) (#69146)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Jun 15, 2020
1 parent b10e6b1 commit 661fd85
Show file tree
Hide file tree
Showing 73 changed files with 194 additions and 183 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { isEsError } from './is_es_error';
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import * as legacyElasticsearch from 'elasticsearch';

const esErrorsParent = legacyElasticsearch.errors._Abstract;

interface RequestError extends Error {
statusCode?: number;
}

export function isEsError(err: RequestError) {
const isInstanceOfEsError = err instanceof esErrorsParent;
const hasStatusCode = Boolean(err.statusCode);

return isInstanceOfEsError && hasStatusCode;
}
3 changes: 2 additions & 1 deletion src/plugins/es_ui_shared/kibana.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "esUiShared",
"version": "kibana",
"ui": true
"ui": true,
"server": true
}
20 changes: 20 additions & 0 deletions src/plugins/es_ui_shared/server/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { isEsError } from '../../__packages_do_not_import__/errors';
28 changes: 28 additions & 0 deletions src/plugins/es_ui_shared/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { isEsError } from './errors';

/** dummy plugin*/
export function plugin() {
return new (class EsUiSharedPlugin {
setup() {}
start() {}
})();
}
13 changes: 0 additions & 13 deletions x-pack/plugins/cross_cluster_replication/server/lib/is_es_error.ts

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/plugins/cross_cluster_replication/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { registerApiRoutes } from './routes';
import { License } from './services';
import { elasticsearchJsPlugin } from './client/elasticsearch_ccr';
import { CrossClusterReplicationConfig } from './config';
import { isEsError } from './lib/is_es_error';
import { isEsError } from './shared_imports';
import { formatEsError } from './lib/format_es_error';

interface CrossClusterReplicationContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { httpServiceMock, httpServerMock } from 'src/core/server/mocks';
import { IRouter, kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { isEsError } from '../../../lib/is_es_error';
import { isEsError } from '../../../shared_imports';
import { formatEsError } from '../../../lib/format_es_error';
import { License } from '../../../services';
import { mockRouteContext } from '../test_lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { isEsError } from './is_es_error';
export { isEsError } from '../../../../src/plugins/es_ui_shared/server';
2 changes: 1 addition & 1 deletion x-pack/plugins/cross_cluster_replication/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LicensingPluginSetup } from '../../licensing/server';
import { IndexManagementPluginSetup } from '../../index_management/server';
import { RemoteClustersPluginSetup } from '../../remote_clusters/server';
import { License } from './services';
import { isEsError } from './lib/is_es_error';
import { isEsError } from './shared_imports';
import { formatEsError } from './lib/format_es_error';

export interface Dependencies {
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/plugins/index_lifecycle_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Dependencies } from './types';
import { registerApiRoutes } from './routes';
import { License } from './services';
import { IndexLifecycleManagementConfig } from './config';
import { isEsError } from './lib/is_es_error';
import { isEsError } from './shared_imports';

const indexLifecycleDataEnricher = async (indicesList: any, callAsCurrentUser: APICaller) => {
if (!indicesList || !indicesList.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { isEsError } from './is_es_error';
export { isEsError } from '../../../../src/plugins/es_ui_shared/server';
2 changes: 1 addition & 1 deletion x-pack/plugins/index_lifecycle_management/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LicensingPluginSetup } from '../../licensing/server';
import { IndexManagementPluginSetup } from '../../index_management/server';
import { License } from './services';
import { IndexLifecycleManagementConfig } from './config';
import { isEsError } from './lib/is_es_error';
import { isEsError } from './shared_imports';

export interface Dependencies {
licensing: LicensingPluginSetup;
Expand Down
13 changes: 0 additions & 13 deletions x-pack/plugins/index_management/server/lib/is_es_error.ts

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { PLUGIN } from '../common';
import { Dependencies } from './types';
import { ApiRoutes } from './routes';
import { License, IndexDataEnricher } from './services';
import { isEsError } from './lib/is_es_error';
import { isEsError } from './shared_imports';
import { elasticsearchJsPlugin } from './client/elasticsearch';

export interface DataManagementContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { isEsError } from './is_es_error';
export { isEsError } from '../../../../src/plugins/es_ui_shared/server';
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ScopedClusterClient, IRouter } from 'src/core/server';
import { LicensingPluginSetup } from '../../licensing/server';
import { SecurityPluginSetup } from '../../security/server';
import { License, IndexDataEnricher } from './services';
import { isEsError } from './lib/is_es_error';
import { isEsError } from './shared_imports';

export interface Dependencies {
security: SecurityPluginSetup;
Expand Down
13 changes: 0 additions & 13 deletions x-pack/plugins/ingest_pipelines/server/lib/is_es_error.ts

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_pipelines/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { PLUGIN_ID, PLUGIN_MIN_LICENSE_TYPE } from '../common/constants';

import { License } from './services';
import { ApiRoutes } from './routes';
import { isEsError } from './lib';
import { isEsError } from './shared_imports';
import { Dependencies } from './types';

export class IngestPipelinesPlugin implements Plugin<void, void, any, any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { isEsError } from './is_es_error';
export { isEsError } from '../../../../src/plugins/es_ui_shared/server';
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_pipelines/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IRouter } from 'src/core/server';
import { LicensingPluginSetup } from '../../licensing/server';
import { SecurityPluginSetup } from '../../security/server';
import { License } from './services';
import { isEsError } from './lib';
import { isEsError } from './shared_imports';

export interface Dependencies {
security: SecurityPluginSetup;
Expand Down
13 changes: 0 additions & 13 deletions x-pack/plugins/license_management/server/lib/is_es_error.ts

This file was deleted.

Loading

0 comments on commit 661fd85

Please sign in to comment.